/** @odoo-module **/
import {keepTwoDecimal,add_dish_key_id,add_number_category_id,add_dinner_type_id,dinnerTypeCategoryComparator,formatId,formatPrice,add_material_item_id,add_net_material_id,formatDishKeyName} from "./ag_grid/tool.js";
import col from './ag_grid/col.js'

import {CreatDishModal} from './components/CreatDishModal.js';
import {CreatMaterialModal} from './components/CreatMaterialModal.js';
import {UnitRatioModal} from './components/UnitRatioModal.js';
import {Toast} from './components/Toast.js';
import {ImportModal} from './components/ImportModal.js';
import {FreqModal} from './components/FreqModal.js';
import {DishListModal} from './components/DishListModal.js';

// console.log(owl);

const {
    markup,
    Component,
    onWillStart,
    useEnv,
    useSubEnv,
    useChildSubEnv,
    useRef,
    useState,
    mount,
    xml,
    whenReady,
    onMounted,
    loadFile,
    onWillUpdateProps,
    useEffect,
    useComponent
} = owl;

import init_grid_options from './ag_grid/gridOptions.js'
import rightGridOptions from './ag_grid/rightGridOptions.js'
import {getRowData,getCountRowData,clearLimitCategoryId,toObj,getRowItemData} from './ag_grid/row.js'
import {commandManager,baseCommand} from './ag_grid/command.js'
import {dinnerTypeNameComparator,dishNumIdNameComparator} from './ag_grid/comparator.js'

const dayKeys = ['day1','day2','day3','day4','day5','day6','day7'];

class Root extends Component {

    setup() {

        // useEnv({  // 这个环境只有root来用
        //     title: '33333',
        // })
        //
        // useSubEnv({
        //     title: 'kkkk',  // 这个环境只有root极其子节点 共用的对象
        //     addDish:(e)=>{
        //        return this.addDish(e)
        //     }
        // })

        useChildSubEnv({// 只会在组件的子组件中挂载公共数据及方法
            selectDish: (e) => {
                return this.selectDish(e)
            },
            closeDishListModal: () => {
                this.state.DishLishModalOpen = false;
                this.state.DishLishData = {};
            },
            closeCreatDishModal: () => {
                this.state.CreatDishModalEdit = false;
                this.state.CreatDishModalOpen = false;
                this.state.CreatDishData = {};
            },
            closeCreatMaterialModal: () => {
                this.state.CreatMaterialModalOpen = false;
                this.state.CreatMaterialModalData = {};
            },
            closeUnitRatioModal: () => {
                this.state.UnitRatioModalOpen = false;
                this.state.UnitRatioModalData = {};
            },
            closeToast: () => {
                this.state.toastOpen = false;
                this.state.toastData = {};
            },
            openToast: (d) => {
                this.state.toastData = d;
                this.state.toastOpen = true;
            },
            closeFreqModal: () => {
                this.state.FreqModalOpen = false;
                this.state.FreqModalData = {};
            },
            openCreatMaterialModal: (obj, callback) => {
                return this.openCreatMaterialModal(obj, callback)
            },
            openUnitRatioModal: (data, callback) => {
                return this.openUnitRatioModal(data, callback)
            },
            spicyHtml: (e) => {
                return this.spicyHtml(e);
            },
            planTopCategoryArr:(categoryId)=>{
                let arr = [];
                arr = this.index.plan_top_category.filter(v=>{
                    return this.dishTopCategoryIds[categoryId] && this.dishTopCategoryIds[categoryId].includes(v.id)
                });
                return arr;
            },
            closeImportModal:() => {
                this.state.ImportModalOpen = false;
                this.state.ImportModalData = {};
            },
            confirmImport: async (data, data_excal)=>{
                return await this.confirmImport(data, data_excal);
            },
            importPlanModelWeekData:(actual_data)=>{
                return this.importPlanModelWeekData(actual_data);
            },
            setPlanWeekData:(data,isNeedCommand,isNeedReset)=>{
                return this.setPlanWeekData(data,isNeedCommand,isNeedReset);
            },
            getDishKeyId:(name,dish_top_category_id)=>{
                return this.getDishKeyId(name,dish_top_category_id)
            },
            getIndex: () => {
                return JSON.parse(JSON.stringify(this.index));
            },
            getGlobal: () => {
                let {number_category,dish_top_category,cooking_category,dish_key,dish_material_color_category,dish_material_shape_category,plan_top_category,dinner_type_category,net_material,material_purchase_unit_category,default_process_id,dish_process_category,material_item,material_map,dish_process_map,default_msupplier_id} = this;

                let _global = {
                    number_category,dish_top_category,cooking_category,dish_key,dish_material_color_category,dish_material_shape_category,plan_top_category,dinner_type_category,net_material,material_purchase_unit_category,default_process_id,dish_process_category,material_item,material_map,dish_process_map,default_msupplier_id};
                return JSON.parse(JSON.stringify(_global));
            },
            getIsGbom:()=>{
                return this.state.isGbom
            },
            getDishBomPrice: (dish_bom) => {
                return this.getDishBomPrice(dish_bom)
            },
            getDishBomByWeighPrice:(dish_bom)=>{
                return this.getDishBomByWeighPrice(dish_bom)
            },
            searchUnit: (material_id) => {
                return this.searchUnit(material_id);
            },
            getWeightRatio:(main_unit_id,unit_id)=>{
                return this.getWeightRatio(main_unit_id,unit_id)
            },
            updateDishBom: (dish_key_id, data, isSave) => {
                return this.updateDishBom(dish_key_id, data, isSave);
            },
            addDishAsync: (e, is_edit,isChangedName) => {
                return this.addDishAsync(e, is_edit,isChangedName)
            },
            addMaterialAsync: (material_obj, is_edit) => {
                return this.addMaterialAsync(material_obj, is_edit)
            },
            addBatchMaterialAsync:(data)=>{
                return this.addBatchMaterialAsync(data)
            },
            addDishAsync_bak: (e,is_edit) => {
                return this.addDishAsync(e,is_edit)
            },
            getMaterialUnitJinRatio: (material_id, unit_id) => {
                return this.getMaterialUnitJinRatio(material_id, unit_id)
            },
            updateMaterialItemBomUnitRatio: (material_id, data) => {
                return this.updateMaterialItemBomUnitRatio(material_id, data);
            },
            LoadSimilarDishBomData:(dish_top_category_id,dish_key_id,dish_name)=>{
                return this.LoadSimilarDishBomData(dish_top_category_id,dish_key_id,dish_name);
            },
            getDishBomById:(dish_key_id)=>{
                return this.getDishBomById(dish_key_id)
            },
            getMaterialPrice:(material_id,unit_id,unit_qty)=>{
                return this.getMaterialPrice(material_id,unit_id,unit_qty)
            },
            getIsDishBomOneEditType:()=>{
                return this.getIsDishBomOneEditType()
            },
            getIsMeatMaterial:(material_id)=>{
                return this.getIsMeatMaterial(material_id)
            },
            get_ke_unit_id:()=>{
                return this.ke_unit_id
            },
            get_jin_unit_id:()=>{
                return this.jin_unit_id
            }
        })

        this.myGrid_ref = useRef('myGrid');
        this.lookGrid_ref = useRef('lookGrid');
        this.planWeekData = [];//表格的基础数据 含已删除
        this.lookPlanWeekData = []; //右侧查看表格的基础数据
        this.lookRowData = []; //右侧查看表格
        this.dragingData = {};//正在拖拽中
        this.needShowTipCell = {};//记录需要提示的菜品单元格

        this.default_process_id = '';
        this.default_msupplier_id = '';
        this.save_dish_bom = [];//dish_bom 要更新的

        this.commander = new commandManager();//撤销 恢复 命令管理
        this.isUndoRedoCommand = false;
        this.LevelScore={ //排序权重
            dinner_type:{
                'dn1':0,
                'dn2':2000000000,
                'dn3':4000000000,
                'dn5':6000000000,
            },
            dinner_type_id:{},
            dish_num_id:{},
            dish_top_category_id:{}
        };
        this.ke_unit_id = 542;
        this.jin_unit_id = 9;
        this.dinner_type = {
            dn1:'早餐',
            dn2:'中餐',
            dn3:'晚餐',
            dn5:'夜餐',
        };
        this.supplyTypeList = [
            {id: 's01', name: '主食点心' },
            {id: 's02', name: '物料' },
            {id: 's03', name: '禽蛋' },
            {id: 's04', name: '牛羊' },
            {id: 's05', name: '家禽' },
            {id: 's06', name: '管理' },
            {id: 's07', name: '物管' },
            {id: 's08', name: '物流' },
            {id: 's09', name: '营销' },
            {id: 's10', name: '鲜猪肉' },
            {id: 's11', name: '加工肉类'},
            {id: 's12', name: '肉' },
            {id:'s1_meat',name:'荤菜类'},
            {id:'s2_vege',name:'素菜类'},
            {id:'s3_rice_etc',name:'米面油蛋'},
            {id:'s4_fruit_drink',name:'水果饮料'},
            {id:'s5_seasoning',name:'干货调料'},
            {id:'s9_others',name:'其他'},
        ];
        this.supplyType = toObj(this.supplyTypeList,'id');

        this.index = {};

        this.creatDishList = [];//创建的菜单列表
        this.addRowMaxId = '';//表格最大的id
        this.rowData = [];//表格数据
        this.countRowData = {};//表格数据汇总
        this.dishKeyMaxId = 0;//菜品最大的id

        this.creatNumberCategoryList = [];//创建的类别序号列表

        this.creatDinnerTypeCategoryList = [];//创建的餐别列表

        this.dishTopCategoryIds = {};//类别下的食材
        this.dishTopCategoryIdsNumbers={};////类别下的序号

        this.dishkeyChangeIds = {};

        this.number_category = {};
        this.dish_top_category = {};
        this.cooking_category = {};
        this.dish_key = {};
        this.dish_material_color_category = {};
        this.dish_material_shape_category = {};
        this.plan_top_category = {};
        this.dinner_type_category = {};
        this.net_material = {};
        this.material_item = {};
        this.cus_loc = {};

        this.state = useState({
            ImportModalOpen:false,
            ImportModalData:{},
            toastOpen: false,
            toastData: {},//提示消息
            CreatDishModalOpen: false,//打开状态
            CreatDishModalEdit:false,//编辑菜品
            CreatDishData: {},
            DishLishModalOpen: false,//打开状态
            DishLishData: {},
            FreqModalOpen: false,
            FreqModalData: {},

            CreatMaterialModalOpen: false,
            CreatMaterialModalEdit: false,
            CreatMaterialModalData: {},

            UnitRatioModalOpen: false,
            UnitRatioModalData: {},

            sidebarShow: 'hide',
            sidebarFilter: {},
            infoShow: 'hide',
            sidebarFilterCheckAll: {},
            dishListModalHead: '',
            tableConfig: {
                color: true,
                cost: true,
                spicy: true,
                costRange: true,
                category:true
            },
            tableForm: [
                {name: '颜色', key: 'color'},
                {name: '辣度', key: 'spicy'},
                {name: '成本', key: 'cost'},
                {name: '成本范围', key: 'costRange'},
                {name: '食材类别', key: 'category'},
            ],
            modelId:'1',
            editConfig:{
                limitCost:'1', //成本限定
                limitCategory:'1',//食材类别限定
                limitSave:'1',//生成菜品限定食材
            },
            lookId:'0',//历史菜单
            lookCompanyId:'0',//其他公司

            canUndo:false,//撤销
            canRedo:false,//恢复

            is_plan_week_show_freq_alert:true,//是否显示使用频次颜色区分
            is_plan_week_show_rule_alert:true,//是否违反规则后菜品加下划线警示

            LoadSecDataFlag:false,
            isGbom:false, //显示毛料true  显示净料false
        })

        onWillStart(this.LoadData);
        onMounted(this.RenderAG);

        this.handleUndoCommand = _.debounce(this.undoCommand,300);
        this.handleRedoCommand = _.debounce(this.redoCommand,300);
        this.handleResume = _.debounce(this.resume,300);
        this.handleClear = _.debounce(this.clear,300);
        this.handle_dish_key_rank = _.debounce(this.dish_key_rank,300);
        this.handle_import_xlsx = _.debounce(this.import_xlsx,300);
        this.handleSave = _.debounce(this.save,300);
        this.handleDownload = _.debounce(this.download,300);
        this.handleGenerateWeekPlan = _.debounce(this.GenerateWeekPlan,300);
        this.handleCopy = _.debounce(this.copy,300);
        this.handleCloseLook = _.debounce(this.closeLook,300);

    }
    getIsMeatMaterial(material_id){
        try {
            let top_category_id = this.material_item[material_id].top_category_id;
            return this.material_top_category[top_category_id].meat_vegetables == 'meat';
        }catch (e){
            return false
        }
    }
    getIsDishBomOneEditType(){
        // 菜品bom的编辑模式是否为1份，否则为100份
        let _flag = true;
        try{
            _flag = !this.index.cost_center_category_settings.is_bom_100;
        }catch (e) {}
        return _flag;
    }
    getDishBomById(dish_key_id){
        dish_key_id = formatId(dish_key_id);
        let dish_bom = this.index.cus_group_bom.filter(v => v.dish_key_id === dish_key_id);
        if(dish_bom.length === 0){
            dish_bom = this.index.dish_bom.filter(v => v.dish_key_id === dish_key_id);
        }
        return dish_bom;
    }
    getMaterialPrice(material_id,unit_id,unit_qty){
        !unit_qty && (unit_qty = 1);
        try {
            let jin_unit_id = this.index.material_purchase_unit_category.find(v=>v.name =='斤').id;
            let purchase_unit_price = this.material_item[material_id].purchase_unit_price;
            let purchase_unit_id = this.material_item[material_id].purchase_unit_id;
            let purchase_unit_ratio = this.getMaterialUnitJinRatio(material_id, purchase_unit_id);
            let unit_ratio = 0;
            if(unit_id == jin_unit_id){
                unit_ratio = 1;
            }else{
                unit_ratio = this.getMaterialUnitJinRatio(material_id,unit_id);
            }
            let price = 0;
            if(purchase_unit_ratio === 0){
                return 0
            }
            try{
                price = purchase_unit_price / purchase_unit_ratio * unit_ratio;
            }catch (e) {}
            price = price * unit_qty;
            return keepTwoDecimal(price)||0
        }catch (e){
            return 0
        }
    }
    // 菜品详情 获取平台推荐配比
    async LoadSimilarDishBomData(dish_top_category_id,dish_key_id,dish_name){
        // console.log('--------LoadSimilarDishBomData------');
        // console.log(dish_top_category_id);
        // console.log(dish_key_id);
        // console.log(dish_name);
        let res;
        if (this.props.PlanWeekLoadSimilarDishBomData) {
            res = await this.props.PlanWeekLoadSimilarDishBomData(dish_top_category_id,dish_key_id,dish_name);
        } else {
            res = await this.LoadTestSimilarDishBomData(dish_top_category_id,dish_key_id,dish_name);
        }
        let {plat_bom_list,similar_dish_key_ids,material_map} = res;
        this.index.material_map = material_map;
        this.material_map = toObj(material_map,'id');
        return res
    }
    async LoadTestSimilarDishBomData(dish_name){
        let randomNumber = Math.floor(Math.random() * 1000);
        // let material_map_id = this.index.material_map[randomNumber].id;
        let material_map = [{
            id:11111,
            name:'冻冻冻-鲜品-食材'
        }];
        let dish_key_id = this.index.dish_key[0].id;

        return new Promise((resolve, reject) => {
            setTimeout(() => {
                let plat_bom_list = [
                    [
                        {
                            bom_qty:13.0,
                            unit_id:9,
                            process_map_id:1,
                            material_map_id:11111
                        },
                    ]
                ];
                let data = {
                    plat_bom_list,
                    similar_dish_key_ids:[dish_key_id],
                    material_map
                };
                resolve(data);
            }, 2000);
        });
    }
    //菜品配比  isSave true更新配比  false临时修改
    async updateDishBom(dish_key_id, data, isSave) {
        dish_key_id = formatId(dish_key_id);

        if (isSave) {
            // console.log(data);
            let res;
            if (this.props.UpdateDishKeyVals) {
                res = await this.props.UpdateDishKeyVals({
                    id: dish_key_id,
                    dish_bom_list: data
                });
            } else {
                res = await this.request({
                    id: dish_key_id,
                    dish_bom_list: data
                });
            }
            data.forEach((v, i) => {
                v.id = res.dish_bom_id_list[i];
                v.dish_key_id = dish_key_id
            });

            let filter_save_dish_bom = this.save_dish_bom.filter(v => formatId(v.dish_key_id) != dish_key_id);
            this.save_dish_bom = filter_save_dish_bom.concat(data);
        }
        let filter_dish_bom = this.index.dish_bom.filter(v => formatId(v.dish_key_id) != dish_key_id);
        this.index.dish_bom = filter_dish_bom.concat(data);

        // 更新菜品的成本
        let dish = this.index.dish_key.find(v=>v.id == dish_key_id);
        let cost = 0;
        data.forEach(bom=>{
            cost += this.getDishBomPrice(bom);
        });
        dish.dish_cost = cost;
        this.dish_key[dish_key_id].dish_cost = cost;
        this.gridOptions.api.redrawRows();

    }
    // 菜品更改名字
    async updateDishName(dish_key_id, dish) {
        // console.log('菜品更改名字');
        this.setPlanWeekData(this.planWeekData);
        // dish_key_id = formatId(dish_key_id);
        // this.gridOptions.api.forEachNode(function (node) {
        //     if (node.data) {
        //         let data = node.data;
        //         for(let i = 1; i　< 8; i++) {
        //             let day = 'day'+i;
        //             if(data[`${day}_key_id`] == dish_key_id){
        //                 node.setDataValue(`${day}_dish_key_name`, dish.name);
        //             };
        //         }
        //     }
        // });
    }
    // 更新 食材 单位转化比
    async updateMaterialItemBomUnitRatio(material_id, data) {
        let material_item_unit_ratio = this.index.material_item_unit_ratio.filter(v => v.material_id != material_id);

        console.log(data);

        let res;
        if (this.props.PlanWeekUpdateMaterialItemBomUnitRatioVals) {
            res = await this.props.PlanWeekUpdateMaterialItemBomUnitRatioVals({
                id: material_id,
                unit_ratio_list: data
            })
            // let ratio_res = {
            //     unit_ratio_obj_list: [
            //         {id: 3, purchase_unit_id: 9, main_unit_bom_unit_ratio: 0.3}
            //     ]
            // }
        } else {
            res = await this.requestUnit(data)
        }

        let {unit_ratio_obj_list} = res;

        console.assert(unit_ratio_obj_list.length >= data.length);

        unit_ratio_obj_list.forEach((obj, i) => {
            obj.material_id = material_id;
            material_item_unit_ratio.push(obj);
        });
        this.index.material_item_unit_ratio = material_item_unit_ratio;
        return data;
    }
    getWeightRatio(main_unit_id,unit_id){
        // this.index.weight_ratio
        let { weight_ratio,material_purchase_unit_category } = this.index;
        let main_unit = material_purchase_unit_category.find(v=>v.id == main_unit_id);
        let unit = material_purchase_unit_category.find(v=>v.id == unit_id);
        let radio = 0;
        if(main_unit && unit && weight_ratio[main_unit.name] && weight_ratio[unit.name]){
            radio = weight_ratio[unit.name]/weight_ratio[main_unit.name]
        }
        return radio;
    }
    getMaterialUnitJinRatio = (material_id,unit_id) =>{
        if(unit_id == this.ke_unit_id){
            return 0.002
        }
        const fillterArr = this.index.material_item_unit_ratio.filter(v => v.material_id == material_id && v.unit_id == unit_id);
        if(fillterArr.length == 0){
            return 0
        }else{
            return fillterArr[0].jin_ratio
        }
    }
    // 搜索 食材有转化比的单位
    searchUnit(material_id) {
        let filterArr = this.index.material_item_unit_ratio.filter(r => r.material_id == material_id);
        let purchase_unit_id_arr = filterArr.map(v => v.unit_id);
        let unitArr = this.index.material_purchase_unit_category.filter(r => purchase_unit_id_arr.includes(r.id));
        return unitArr;
    }
    // 根据DishBom计算成本价
    getDishBomPrice(data){
        // dish_bom:
        // dish_key_id
        // expansion
        // gbom_qty_high
        // gbom_qty_low
        // gbom_qty_mid
        // id
        // material_id
        // material_sequence_no
        // process_id
        // unit_id
        // console.log(data);
        // console.log(owl.index.material_item_bom_unit_ratio);
        let price = 0;
        let {gbom_qty_high,unit_id,material_id} = data;
        if(gbom_qty_high && unit_id && material_id){
            let main_unit_bom_unit_ratio = this.getMainUnitBomUnitRatio(material_id,unit_id);
            console.assert(main_unit_bom_unit_ratio,material_id,unit_id);
            try {
                let main_price = this.material_item[material_id].main_price;
                // price =  formatPrice(data.gbom_qty_high * 0.01 * main_price / main_unit_bom_unit_ratio);
                price =  formatPrice(gbom_qty_high * 0.01 * main_price * main_unit_bom_unit_ratio);
            }catch (e) {}
        }
        return price;
    }
    getDishBomByWeighPrice(data){
        let price = 0;
        let {gbom_qty_mid,unit_id,material_id} = data;
        if(gbom_qty_mid && unit_id && material_id){
            let main_unit_bom_unit_ratio = this.getMainUnitBomUnitRatio(material_id,unit_id);
            console.assert(main_unit_bom_unit_ratio,material_id,unit_id);
            try {
                let main_price = this.material_item[material_id].main_price;
                price =  formatPrice(gbom_qty_mid * 0.01 * main_price * main_unit_bom_unit_ratio);
            }catch (e) {}
        }
        return price;

    };
    getMainUnitBomUnitRatio(material_id,unit_id){
        let main_unit_id = this.material_item[material_id].main_unit_id;
        const main_item = this.index.material_item_unit_ratio.find(v => v.material_id == material_id && v.unit_id == main_unit_id);
        const unit_item = this.index.material_item_unit_ratio.find(v => v.material_id == material_id && v.unit_id == unit_id);
        let ratio = 0;
        try {
            ratio = unit_item.jin_ratio/main_item.jin_ratio;
        }catch (e) {}
        return ratio
    }
    // 类别对应的食材
    setDishTopCategoryIds(){
        let obj = {};
        this.index.dish_key.forEach(v=>{
            !obj[v.dish_top_category_id] && (obj[v.dish_top_category_id] = []);
            obj[v.dish_top_category_id].push(v.plan_top_category_id);
        });
        this.dishTopCategoryIds = obj;

    }
    // 类别下对应的序号
    setDishTopCategoryIdsNumbers(){
        let obj = {};
        this.index.dish_top_category.forEach(top=>{
            this.index.number_category.forEach(number=>{
                !obj[top.id] && (obj[top.id] = JSON.parse(JSON.stringify(top)));
                !obj[top.id].children && (obj[top.id].children = []);
                number.name.includes(top.name) && obj[top.id].children.push(JSON.parse(JSON.stringify(number)))
            });
        })
        this.dishTopCategoryIdsNumbers = obj;
        // console.log(this.dishTopCategoryIdsNumbers);
    }

    // 查看历史订单
    lookChange(){
        this.state.lookId && (this.state.lookCompanyId = '0');
        if(this.state.lookId === '0'){
            return;
        }
        this.lookPlanWeekData = this.index.plan_week_overall_show.filter(v=>v.week==this.state.lookId);
        // console.log(this.lookPlanWeekData);
        this.lookPlanWeekData.forEach((v,i)=>{
            v.id = i+1;
            v.LevelScore = this.getLevelScore(v);
        })
        this.lookRowData = getRowData(this,this.lookPlanWeekData);
        // console.log(this.lookPlanWeekData);
        if(!this.gridOptions_look){
            this.RenderAG_look();
        }else{
            this.gridOptions_look.api.setRowData(this.lookRowData);
        }
    }
    //参考其他公司
    async lookCompanyChange(){
        if(!this.state.LoadSecDataFlag){
            await this.LoadSecData()
        }
        this.state.lookCompanyId && (this.state.lookId = '0');
        if(this.state.lookCompanyId === '0'){
            return;
        }
        let key = this.state.lookCompanyId.split('|');
        this.lookPlanWeekData = this.index.other_company[key[0]][key[1]];
        let dish_key = toObj(this.index.other_dish_key[key[0]][key[1]],'id');
        let number_category_arr = this.index.other_number_category[key[0]][key[1]];
        let number_category = toObj(number_category_arr,'id');
        let dinner_type_category_arr = this.index.other_dinner_type_category[key[0]][key[1]];
        let dinner_type_category = toObj(dinner_type_category_arr,'id');
        let LevelScore = this.setLevelScore({number_category:number_category_arr,dinner_type_category:dinner_type_category_arr});
        // console.log(this.lookPlanWeekData);
        this.lookPlanWeekData.forEach((v,i)=>{
            v.id = i+1;
            v.LevelScore = this.getLevelScore(v,LevelScore);
        });
        this.lookRowData = getRowData(this,this.lookPlanWeekData,{dish_key:dish_key,number_category:number_category,dinner_type_category:dinner_type_category});
        if(!this.gridOptions_look){
            this.RenderAG_look();
        }else{
            this.gridOptions_look.api.setRowData(this.lookRowData);
        }
    }
    RenderAG_look(){
        let _this = this;
        this.gridOptions_look = Object.assign({}, rightGridOptions(_this), {
            rowData: this.lookRowData,
            context: {
                owl_widget: _this
            },
        });
        this.agGrid_look = new agGrid.Grid(this.lookGrid_ref.el, this.gridOptions_look);

    }


    async LoadTestData() {

        let cooking_category = await fetch('./json/cooking_category.json')
            .then((response) => response.json());
        let dish_family = await fetch('./json/dish_family.json')
            .then((response) => response.json());
        let dish_key = await fetch('./json/dish_key.json')
            .then((response) => response.json());
        let dish_material_color_category = await fetch('./json/dish_material_color_category.json')
            .then((response) => response.json());
        let dish_material_shape_category = await fetch('./json/dish_material_shape_category.json')
            .then((response) => response.json());
        let dish_top_category = await fetch('./json/dish_top_category.json')
            .then((response) => response.json());
        let other_company = await fetch('./json/other_company.json')
            .then((response) => response.json());
        let number_category = await fetch('./json/number_category.json')
            .then((response) => response.json());
        let plan_week_overall_show = await fetch('./json/plan_week_overall_show.json')
            .then((response) => response.json());
        let plan_top_category = await fetch('./json/plan_top_category.json')
            .then((response) => response.json());
        let plan_week_model_no_list = await fetch('./json/plan_week_model_no_list.json')
            .then((response) => response.json());
        let user_config = await fetch('./json/user_config.json')
            .then((response) => response.json());
        let other_dish_key = await fetch('./json/other_dish_key.json')
            .then((response) => response.json());
        let history_week = await fetch('./json/history_week.json')
            .then((response) => response.json());
        let model_history_week = await fetch('./json/model_history_week.json')
            .then((response) => response.json());
        let other_number_category = await fetch('./json/other_number_category.json')
            .then((response) => response.json());
        let dish_sub_category = await fetch('./json/dish_sub_category.json')
            .then((response) => response.json());
        let dinner_mode_category = await fetch('./json/dinner_mode_category.json')
            .then((response) => response.json());
        let dinner_type_category = await fetch('./json/dinner_type_category.json')
            .then((response) => response.json());
        let org_group_category = await fetch('./json/org_group_category.json')
            .then((response) => response.json());
        let other_dinner_type_category = await fetch('./json/other_dinner_type_category.json')
            .then((response) => response.json());

        let dish_process_category = await fetch('./json/dish_process_category.json')
            .then((response) => response.json());
        let material_purchase_unit_category = await fetch('./json/material_purchase_unit_category.json')
            .then((response) => response.json());
        let net_material = await fetch('./json/net_material.json')
            .then((response) => response.json());

        let daily_cost_category = await fetch('./json/daily_cost_category.json')
            .then((response) => response.json());
        let msupplier = await fetch('./json/msupplier.json')
            .then((response) => response.json());
        let material_top_category = await fetch('./json/material_top_category.json')
            .then((response) => response.json());
        let purchase_category = await fetch('./json/purchase_category.json')
            .then((response) => response.json());

        let dish_process_map = await fetch('./json/dish_process_map.json')
            .then((response) => response.json());
        let plan_week_model_overall_cus_special = await fetch('./json/plan_week_model_overall_cus_special.json')
            .then((response) => response.json());
        let cus_loc = await fetch('./json/cus_loc.json')
            .then((response) => response.json());

        let dish_bom = await fetch('./json/dish_bom.json')
            .then((response) => response.json());
        let material_item = await fetch('./json/material_item.json')
            .then((response) => response.json());
        let material_item_unit_ratio = await fetch('./json/material_item_unit_ratio.json')
            .then((response) => response.json());
        let cost_center_material_cfg = await fetch('./json/cost_center_material_cfg.json')
            .then((response) => response.json());
        let cus_group_bom = await fetch('./json/cus_group_bom.json')
            .then((response) => response.json());

        let cost_center_category_settings = await fetch('./json/cost_center_category_settings.json')
            .then((response) => response.json());


        return {
            cooking_category,
            dish_family,
            dish_key,
            dish_material_shape_category,
            dish_top_category,
            dish_material_color_category,
            number_category,
            plan_week_overall_show,
            plan_top_category,
            plan_week_model_no_list,
            other_company,
            user_config,
            other_dish_key,
            history_week,
            model_history_week,
            other_number_category,
            dish_sub_category,
            dinner_mode_category,
            dinner_type_category,
            org_group_category,
            other_dinner_type_category,
            dish_process_category,
            material_purchase_unit_category,
            net_material,
            daily_cost_category,
            msupplier,
            material_top_category,
            purchase_category,
            dish_process_map,
            plan_week_model_overall_cus_special,
            cus_loc,
            dish_bom,
            material_item,
            material_item_unit_ratio,
            cost_center_material_cfg,
            cus_group_bom,
            cost_center_category_settings
        }

    }

    async LoadTestOtherData(){
        let dish_bom = await fetch('./json/sec_data/dish_key_data/dish_bom.json')
            .then((response) => response.json());
        let cus_group_bom = await fetch('./json/sec_data/dish_key_data/cus_group_bom.json')
            .then((response) => response.json());
        let dish_key = await fetch('./json/sec_data/dish_key_data/dish_key.json')
            .then((response) => response.json());
        return {
            dish_bom,
            cus_group_bom,
            dish_key
        }
    }

    async LoadTestSecData() {
        let material_item = await fetch('./json/sec_data/material_data/material_item.json')
            .then((response) => response.json());
        let material_item_unit_ratio = await fetch('./json/sec_data/material_data/material_item_unit_ratio.json')
            .then((response) => response.json());
        // let material_map = await fetch('./json/sec_data/material_data/material_map.json')
        //     .then((response) => response.json());
        let cost_center_material_cfg = await fetch('./json/sec_data/material_data/cost_center_material_cfg.json')
            .then((response) => response.json());


        return {
            material_item,
            material_item_unit_ratio,
            // material_map,
            cost_center_material_cfg,
        }
    }

    // 更换模板
    async selectModel(e){
        // console.log(this.state.modelId);
        if(this.state.canUndo){
            this.state.toastData = {
                msg:'请先【保存】当前模板。'
            };
            this.state.toastOpen = true;
            setTimeout(()=>{
                this.state.modelId = this.modelId;
                document.getElementById("modelId").value = this.modelId;
            },500)
        }else{
            let modelId = this.state.modelId;
            this.modelId = modelId;
            let data = this.index.plan_week_model_no_list.find(v => v.plan_week_manual_model == modelId);
            let list = data.vals_list || [];
            list = list.filter(v=>v.sales_type == 'kuai');
            let tese_list = this.index.plan_week_model_overall_cus_special.filter(v => v.plan_week_manual_model == modelId)||[];
            list = list.concat(tese_list);
            this.setPlanWeekData(list,0,1);
            if(e){
                console.log('-----更换模板----');
                console.log(modelId);
                if (this.props.PlanWeekModelChangeModelNo) {
                    await this.props.PlanWeekModelChangeModelNo(modelId);
                }
            }
        }
    }
    set_cost_center_material_cfg_obj(){
        let {cost_center_material_cfg} = this.index;
        let cost_center_material_cfg_obj = {};
        cost_center_material_cfg.forEach(v=>{
            let { material_id } = v;
            !cost_center_material_cfg_obj[material_id] && (cost_center_material_cfg_obj[material_id] = []);
            cost_center_material_cfg_obj[material_id].push(v);
        })
        this.cost_center_material_cfg_obj = cost_center_material_cfg_obj;
    }
    update_material_item_by_cost_center_material_cfg(){
        this.index.material_item.forEach(v=>{
            try{
                let cfg = this.cost_center_material_cfg_obj[v.id][0];
                v.default_msupplier_id =  cfg.msupplier_id;
                v.purchase_unit_id =  cfg.unit_id;
                v.purchase_unit_price =  cfg.unit_price;
                v.admin_ratio =  cfg.admin_ratio;
            }catch (e) {}
        })
    }
    //设置表格基础数据  isSetRowData更新表格 isNeedCommand记录操作  isNeedReset操作记录命令重置
    setPlanWeekData(data,isNeedCommand,isNeedReset){
        let oldPlanWeekData = JSON.parse(JSON.stringify(this.planWeekData));
        this.planWeekData = [];
        this.addRowMaxId = 0;
        // console.log(this.dishkeyChangeIds);
        data.forEach(v=>{
            if(!v.dish_num_id && !v.cus_loc_id){ return; }
            let newItem = JSON.parse(JSON.stringify(v));
            this.addRowMaxId++;
            newItem.id = this.addRowMaxId;
            newItem.minCost = 0;
            newItem.maxCost = 2;
            newItem.LevelScore = this.getLevelScore(newItem);
            for(let i = 1; i　< 8; i++) {
                let id = v['day'+i+'_key_id'];
                if(this.dishkeyChangeIds[id]){
                    // console.log(newItem);
                    newItem['day'+i+'_key_id'] = this.dishkeyChangeIds[id];
                }
            }
            if(newItem.te_pei_json){
                for(let i = 1; i　< 8; i++) {
                    newItem.te_pei_json['day'+i].forEach((item,index)=>{
                        if(this.dishkeyChangeIds[item]){
                            newItem.te_pei_json['day'+i][index] = this.dishkeyChangeIds[item];
                        }
                    })
                }
            }
            this.planWeekData.push(newItem)
        });
        this.rowData = getRowData(this,this.planWeekData);
        this.countRowData = getCountRowData(this.rowData);
        if(this.gridOptions){
            this.gridOptions.api.setRowData([]);
            this.gridOptions.api.setRowData(this.rowData);
            this.gridOptions.api.redrawRows();
            // this.refreshCells();
            if(isNeedCommand){
                this.sentCommand(data,oldPlanWeekData,'setRowData')
            }
            if(isNeedReset){
                this.commander.reset();
            }
        }
    }

    copy(){
        if(this.state.lookId != '0'){
            // 复制历史菜单
            let data = this.index.plan_week_overall_show.filter(v=>v.week==this.state.lookId);
            this.setPlanWeekData(data,1);
        }
        if(this.state.lookCompanyId != '0'){
            console.log(this.lookRowData);
            // 复制其他公司
            // 校验是否有名称重复的餐别
            let obj = {};
            let flag = true;
            this.lookRowData.forEach(v=>{
                let {dinner_type,name,id} = v.dinner_type_category;
                if(!obj[`${dinner_type}||${name}`]){
                    obj[`${dinner_type}||${name}`] = id;
                }
                if(obj[`${dinner_type}||${name}`] != id){
                    flag = false;
                }
            });
            if(!flag){
                this.state.toastData = {
                    msg:'餐别名称重复，暂不支持复制。'
                };
                this.state.toastOpen = true;
                return;
            }

            this.copyRowData(this.lookRowData);
        }
    }
    // 将别的表格数据复制
    copyRowData(rowData,isUpdataDish){
        let data = JSON.parse(JSON.stringify(rowData));
        data.forEach(v=>{
            for (let i = 1; i < 8; i++) {
                // console.log(v['day'+i+'_dish_key']);
                let dish = v['day'+i+'_dish_key'];
                if(dish && dish.name && dish.dish_top_category_id){
                    // 菜品是否需要创建
                    let id = this.getDishKeyId(dish.name,dish.dish_top_category_id);
                    if(!id){
                        // 没有菜品
                        id = this.addDish(v['day'+i+'_dish_key'])
                    }else{
                        isUpdataDish && this.updataDish(dish,id)
                    }
                    v['day'+i+'_key_id'] = id;
                }
            }
            v.dish_num_id = this.getDishNumId(v.number_category,1);
            v.dinner_type_id = this.getDinnerTypeCategoryId(v.dinner_type_category,1);
        });
        clearLimitCategoryId(data);
        this.setDishTopCategoryIds();
        // console.log('-----');
        // console.log(data);
        this.setPlanWeekData(data,1);
    }

    //重置
    resume(){
        let data = this.index.plan_week_model_no_list.find(v => v.plan_week_manual_model == this.state.modelId);
        let list = data.vals_list || [];
        this.setPlanWeekData(list,1);
    }
    //清除
    clear(){
        let planWeekData = JSON.parse(JSON.stringify(this.planWeekData));
        planWeekData.forEach(v=>{
            dayKeys.forEach(day=>{
                v[day+'_key_id'] = 0;
                v[day+'_limit_category_id'] = 0;
            })
        })
        this.setPlanWeekData(planWeekData,1);
    }

    dish_key_rank() {
        if (this.props.GetDishKeyRank) {
            this.props.GetDishKeyRank();
        }
        // alert('ok');
    }

    async LoadSecData() {
        let load_func;
        if (this.props.LoadMaterialRelatedData) {
            load_func = this.props.LoadMaterialRelatedData;
        } else {
            load_func = this.LoadTestSecData.bind(this);
        }

        let data = await load_func();
        let {
            material_item,
            material_item_unit_ratio,
            // material_map,
            cost_center_material_cfg,
        } = data;


        this.index.material_item = material_item;
        this.index.material_item_unit_ratio = material_item_unit_ratio;
        // this.index.material_map = material_map;
        this.index.cost_center_material_cfg = cost_center_material_cfg;
        this.set_cost_center_material_cfg_obj();
        this.update_material_item_by_cost_center_material_cfg();

        this.material_item = toObj(material_item,'id');
        // this.material_map = toObj(material_map,'id');

        this.update_index_dish_key_cost();

        // let material_dish_bom = {};
        // dish_bom.forEach(v => {
        //     !material_dish_bom[v.material_id] && (material_dish_bom[v.material_id] = []);
        //     material_dish_bom[v.material_id].push(v);
        // });
        // this.material_dish_bom = material_dish_bom;
        this.state.LoadSecDataFlag = true;
    }

    async LoadData() {
        // console.log('加载数据...') // 开辟加载父类数据结构逻辑!!!
        let load_func = this.props.LoadData ? this.props.LoadData : this.LoadTestData.bind(this);

        let data = await load_func();

        let {
            cooking_category,
            dish_family,
            dish_key,
            dish_material_shape_category,
            dish_top_category,
            dish_material_color_category,
            number_category,
            plan_week_overall_show,
            plan_top_category,
            plan_week_model_no_list,
            other_company,
            user_config,
            other_dish_key,
            history_week,
            model_history_week,
            other_number_category,
            dish_sub_category,
            dinner_mode_category,
            dinner_type_category,
            org_group_category,
            other_dinner_type_category,
            dish_process_category,
            material_purchase_unit_category,
            net_material,
            daily_cost_category,
            msupplier,
            material_top_category,
            purchase_category,
            dish_process_map,
            plan_week_model_overall_cus_special,
            cus_loc,
            dish_bom,
            material_item,
            material_item_unit_ratio,
            cost_center_material_cfg,
            cus_group_bom,
            cost_center_category_settings
        } = data;

        dish_top_category.forEach(v => {
            v.name = v.name_cn;
        });
        dinner_type_category.forEach(v => {
            v.dinner_type_name = this.dinner_type[v.dinner_type];
        });
        let default_msupplier_id = '';
        msupplier.forEach(v => {
            v.supply_type_name = this.supplyType[v.supply_type].name;
            if(v.is_self_supplier_company){
                default_msupplier_id = v.id;
            }
        });
        this.default_msupplier_id = default_msupplier_id;
        let weight_ratio = {
            '两':10,
            '克':500,
            '公斤':0.5,
            '斤':1
        };
        this.index = {
            cooking_category,
            dish_family,
            dish_key,
            dish_material_shape_category,
            dish_top_category,
            dish_material_color_category,
            number_category,
            plan_week_overall_show,
            plan_top_category,
            plan_week_model_no_list,
            other_company,
            user_config,
            other_dish_key,
            history_week,
            model_history_week,
            other_number_category,
            dish_sub_category,
            dinner_mode_category,
            dinner_type_category,
            org_group_category,
            other_dinner_type_category,
            dish_process_category,
            material_purchase_unit_category,
            net_material,
            daily_cost_category,
            msupplier,
            material_top_category,
            purchase_category,
            weight_ratio,
            dish_process_map,
            plan_week_model_overall_cus_special,
            cus_loc,
            dish_bom,
            material_item,
            material_item_unit_ratio,
            cost_center_material_cfg,
            cus_group_bom,
            cost_center_category_settings
        };

        this.set_cost_center_material_cfg_obj();
        this.update_material_item_by_cost_center_material_cfg();
        this.material_item = toObj(material_item,'id');

        this.setLevelScore();

        this.number_category = toObj(number_category,'id');
        this.dish_top_category = toObj(dish_top_category,'id');
        this.cooking_category = toObj(cooking_category,'id');

        this.update_index_dish_key_cost();
        this.dish_material_color_category = toObj(dish_material_color_category,'id');
        this.dish_material_shape_category = toObj(dish_material_shape_category,'id');
        this.plan_top_category = toObj(plan_top_category,'id');
        this.dinner_type_category = toObj(dinner_type_category,'id');
        this.net_material = toObj(net_material,'id');
        this.material_purchase_unit_category = toObj(material_purchase_unit_category,'id');
        this.dish_process_category = toObj(dish_process_category,'id');
        this.dish_process_map = toObj(dish_process_map,'id');
        this.cus_loc = toObj(cus_loc,'cus_loc_id');

        this.default_process_id = dish_process_category.find(v=>v.name == '无').id;
        this.state.isGbom = this.index.user_config.bom_qty_type == 'bom_qty';

        let dishKeyIds = dish_key.map(v=>{ return v.id});
        this.dishKeyMaxId = Math.max(...dishKeyIds) + 1;
        // console.log(this.dishKeyMaxId);
        this.setDishTopCategoryIds();
        this.setDishTopCategoryIdsNumbers();
        this.setConfig();
        this.setSidebarFilter();
        this.state.modelId = this.props.model_no ? this.props.model_no : plan_week_model_no_list[0].plan_week_manual_model;//模板默认选择第一个
        this.modelId = this.state.modelId;
        await this.selectModel();

        this.loadDishKeyRelatedData();

    }
    async loadDishKeyRelatedData(){
        let load_func;
        if (this.props.LoadDishKeyRelatedData) {
            load_func = this.props.LoadDishKeyRelatedData;
        } else {
            load_func = this.LoadTestOtherData.bind(this);
        }

        let data = await load_func();
        let {
            dish_bom,
            cus_group_bom,
            dish_key
        } = data;
        this.index.dish_bom = dish_bom;
        this.index.cus_group_bom = cus_group_bom;
        this.index.dish_key = dish_key;
        this.update_index_dish_key_cost();
        this.setDishTopCategoryIds();


    }
    update_index_dish_key_cost(){
        this.index.dish_key.forEach(d=>{
            let dish_cost = 0;
            let dish_bom_list = this.getDishBomById(d.id);
            dish_bom_list.forEach(v=>{
                let price = 0;
                let { gbom_qty_high,unit_id,material_id } = v;
                if(gbom_qty_high && unit_id && material_id){
                    price = this.getMaterialPrice(material_id,unit_id,gbom_qty_high);
                    price = price*0.01;
                    price = formatPrice(price);
                }
                dish_cost += price
            })
            dish_cost = formatPrice(dish_cost);
            d.dish_cost = dish_cost;
        })
        this.dish_key = toObj(this.index.dish_key,'id');
    }
    // 排序分值
    setLevelScore(data){
        let dinner_type_id = {};
        let dish_num_id = {};
        let dish_top_category_id = {};
        if(data){
            let {number_category,dinner_type_category} = data;
            let LevelScore = JSON.parse(JSON.stringify(this.LevelScore));
            dinner_type_category.sort((a,b)=>{return dinnerTypeCategoryComparator(a,b)});
            dinner_type_category.forEach((v,i)=>{
                dinner_type_id[v.id] = i*1000000000000
            });
            number_category.sort((a,b)=>{return dishNumIdNameComparator(a.name,b.name)});
            number_category.forEach((number,k)=>{
                let i = this.index.dish_top_category.findIndex(v=>number.name.includes(v.name));
                dish_num_id[number.id] = (i+1)*10000000+((k+1)*100000);
            });
            let _i = this.index.dish_top_category.findIndex(v=>v.id == 4);
            dish_num_id['cus'] = (_i+1)*10000000;
            LevelScore.dish_num_id = dish_num_id;
            LevelScore.number_category = toObj(number_category,'id');
            LevelScore.dinner_type_category = toObj(dinner_type_category,'id');
            return LevelScore;
        }else{
            this.index.dinner_type_category.sort((a,b)=>{return dinnerTypeCategoryComparator(a,b)});
            this.index.dinner_type_category.forEach((v,i)=>{
                dinner_type_id[v.id] = i*1000000000000
            });
            this.index.dish_top_category.sort((a,b)=>{return a.category_order-b.category_order});
            this.index.number_category.sort((a,b)=>{return dishNumIdNameComparator(a.name,b.name)});
            this.index.number_category.forEach((number,k)=>{
                let i = this.index.dish_top_category.findIndex(v=>number.name.includes(v.name));
                dish_num_id[number.id] = (i+1)*10000000+((k+1)*100000);
            })
            let _i = this.index.dish_top_category.findIndex(v=>v.id == 4);
            dish_num_id['cus'] = (_i+1)*10000000;
            this.index.dish_top_category.forEach((top,k)=>{
                if(top.id == 4){
                    dish_top_category_id[top.id] = 0
                }else{
                    dish_top_category_id[top.id] = (k+1)*1000
                }
            });
            this.LevelScore.dinner_type_id = dinner_type_id;
            this.LevelScore.dish_num_id = dish_num_id;
            this.LevelScore.dish_top_category_id = dish_top_category_id;
        }
    }
    getLevelScore(v,LevelScore){
        let score = 0;
        let dinner_type_category;
        let number_category;
        if(!LevelScore){
            LevelScore =  this.LevelScore;
            dinner_type_category = this.dinner_type_category;
            number_category = this.number_category;
        }else{
            dinner_type_category = LevelScore.dinner_type_category;
            number_category = LevelScore.number_category;
        }
        let is_te_pei = !!v.te_pei_json;
        if(is_te_pei){
            score = LevelScore.dinner_type_id[v.dinner_type_id] + LevelScore.dish_num_id['cus'] + LevelScore.dish_top_category_id[4] + ((v.sequence_tag||0)*1000);
        }else{
            score = LevelScore.dinner_type_id[v.dinner_type_id] + LevelScore.dish_num_id[v.dish_num_id] + LevelScore.dish_top_category_id[v.dish_top_category_id];
        }
        //早餐的点心排前面
        if(dinner_type_category[v.dinner_type_id].dinner_type == 'dn1' && v.dish_top_category_id == 8 && number_category[v.dish_num_id].dish_top_category_id != 4){
            score = score - LevelScore.dish_num_id[v.dish_num_id] + (LevelScore.dish_num_id[v.dish_num_id]/10000000);
        }
        if(v.id){
            score += (v.id*2);
        }
        return score;
    }

    setConfig(){
        // is_plan_week_show_shape
        // is_plan_week_show_xiafan
        let { user_config }=this.index;
        this.state.sidebarShow = user_config.is_plan_week_show_left_panel?'show':'hide';
        this.state.tableConfig.color = !!user_config.is_plan_week_show_color;
        this.state.tableConfig.spicy = !!user_config.is_plan_week_show_spicy;
        this.state.tableConfig.cost = !!user_config.is_plan_week_show_cost;
        this.state.tableConfig.costRange = !!user_config.is_plan_week_show_cost_range;
        this.state.editConfig.limitCost = user_config.is_plan_week_set_dish_by_cost_range?'1':'0';
        this.state.editConfig.limitCategory = user_config.is_plan_week_set_by_material_category?'1':'0';
        this.state.editConfig.limitSave = user_config.is_plan_week_set_by_material_category?'1':'0';

        this.state.is_plan_week_show_freq_alert = user_config.is_plan_week_show_freq_alert;
        this.state.is_plan_week_show_rule_alert = user_config.is_plan_week_show_rule_alert;
    }

    get ModelNo() {
        return this.state.modelId;
    }
    getSaveCreatDishList(){
        let savePlanWeekData = this.planWeekData.filter(v=>!v.isDeleted);
        let creatDishObj = toObj(this.creatDishList,'id');
        let saveIds = [];
        savePlanWeekData.forEach(v=>{
            for(let i = 1; i　< 8; i++) {
                if(creatDishObj[v[`day${i}_key_id`]]){
                    saveIds.push(v[`day${i}_key_id`]);
                }
            }
            if(v.te_pei_json){
                for(let i = 1; i　< 8; i++) {
                    v.te_pei_json[`day${i}`].forEach(pei_id=>{
                        if(creatDishObj[pei_id]){
                            saveIds.push(pei_id);
                        }
                    })
                }
            }
        })
        let list = this.creatDishList.filter(v=>saveIds.includes(v.id));
        return list;
    }

    // 保存
    async save() {
        if(!this.state.canUndo){
            return;
        }
        console.log('save');
        // 新菜单列表 this.creatDishList
        // 表格的基础数据 this.planWeekData
        console.log('-------------保存-新建菜品列表-------------');
        let creatDishList = this.getSaveCreatDishList();
        let noDishTopCategoryId = creatDishList.filter(v=>!v.dish_top_category_id).map(v=>v.name);
        if(noDishTopCategoryId.length > 0){
            this.state.toastData = {
                msg:'特色配菜 “ '+noDishTopCategoryId.join('、')+' ” 没有类别，请先设置。'
            };
            this.state.toastOpen = true;
            throw '特色配菜没有类别';
            return;
        }

        console.log(creatDishList);
        console.log('-------------保存-新建类别序号列表-------------');
        console.log(this.creatNumberCategoryList);
        console.log('-------------保存-新建餐别列表-------------');
        console.log(this.creatDinnerTypeCategoryList);

        console.log('-------------保存-数据-------------');
        let savePlanWeekData = this.planWeekData.filter(v=>!v.isDeleted && !v.te_pei_json);
        let savePlanWeekDataWithCus = this.planWeekData.filter(v=>!v.isDeleted && v.te_pei_json);
        let no_cus_loc_ids = savePlanWeekDataWithCus.filter(v=>!v.cus_loc_id);
        if(savePlanWeekData.length == 0 && savePlanWeekDataWithCus.length == 0){
            this.state.toastData = {
                msg:'保存时至少要有一条数据。'
            };
            this.state.toastOpen = true;
            throw '保存时至少要有一条数据';
            return;
        }
        if(no_cus_loc_ids.length>0){
            this.state.toastData = {
                msg:'特色没有客户，请先设置。'
            };
            this.state.toastOpen = true;
            throw '特色没有户';
            return;
        }


        console.log(savePlanWeekData);
        console.log('客户+特色',savePlanWeekDataWithCus);

        if (this.props.UpdatePlanWeekModelWithCusOverShowData) {

            let creatNumberCategoryList = this.creatNumberCategoryList;
            let creatDinnerTypeCategoryList = this.creatDinnerTypeCategoryList;//新建餐别列表

            try {
                await this.props.UpdatePlanWeekModelWithCusOverShowData(this.ModelNo,creatDishList, creatNumberCategoryList, creatDinnerTypeCategoryList, savePlanWeekData, savePlanWeekDataWithCus);

                let index = this.index.plan_week_model_no_list.findIndex(v => v.plan_week_manual_model == this.ModelNo);
                this.index.plan_week_model_no_list[index].vals_list = savePlanWeekData;
                let plan_week_model_overall_cus_special = this.index.plan_week_model_overall_cus_special.filter(v => v.plan_week_manual_model != this.ModelNo);
                this.index.plan_week_model_overall_cus_special = plan_week_model_overall_cus_special.concat(savePlanWeekDataWithCus);
                this.commander.reset();
            }catch (e) {
                throw e;
            }
        }else{
            let index = this.index.plan_week_model_no_list.findIndex(v => v.plan_week_manual_model == this.ModelNo);
            this.index.plan_week_model_no_list[index].vals_list = savePlanWeekData;
            let plan_week_model_overall_cus_special = this.index.plan_week_model_overall_cus_special.filter(v => v.plan_week_manual_model != this.ModelNo);
            this.index.plan_week_model_overall_cus_special = plan_week_model_overall_cus_special.concat(savePlanWeekDataWithCus);

            this.commander.reset();
        }
    }

    async download() {
        let savePlanWeekData = this.planWeekData.filter(v=>!v.isDeleted && !v.te_pei_json);
        let savePlanWeekDataWithCus = this.planWeekData.filter(v=>!v.isDeleted && v.te_pei_json);
        if(savePlanWeekData.length == 0 && savePlanWeekDataWithCus.length == 0){
            this.state.toastData = {
                msg:'无数据，不能下载。'
            };
            this.state.toastOpen = true;
            return;
        }
        console.log(savePlanWeekData);
        console.log('客户+特色',savePlanWeekDataWithCus);
        await this.save();
        if (this.props.DownLoadPlanWeekModelOverShowData) {
            let creatNumberCategoryList = this.creatNumberCategoryList;

            await this.props.DownLoadPlanWeekModelOverShowData(this.ModelNo, this.creatDishList, creatNumberCategoryList, savePlanWeekData);

        } else {
            console.log('下载测试');
        }
    }

    // 导入
    import_xlsx(){
        let {dinner_type_category,dish_top_category} = this.index;
        this.state.ImportModalData = {
            dinner_type_category,dish_top_category
        };
        this.state.ImportModalOpen = true;
    }
    //导入提交
    async confirmImport(data, excel_stream){
        console.log('-------导入------');
        console.log(data);

        if (this.props.ImportPlanWeekModelData) {
            let data_config = await this.props.ImportPlanWeekModelData(excel_stream);
            return data_config;
        } else {
            let cost_center_material_cfg = await fetch('./json/import_data/cost_center_material_cfg.json')
                .then((response) => response.json());
            let cus_group_bom = await fetch('./json/import_data/cus_group_bom.json')
                .then((response) => response.json());
            let dinner_type_category_data = await fetch('./json/import_data/dinner_type_category_data.json')
                .then((response) => response.json());
            let dish_bom = await fetch('./json/import_data/dish_bom.json')
                .then((response) => response.json());
            let dish_key = await fetch('./json/import_data/dish_key.json')
                .then((response) => response.json());
            let dish_num_data = await fetch('./json/import_data/dish_num_data.json')
                .then((response) => response.json());
            let material_item = await fetch('./json/import_data/material_item.json')
                .then((response) => response.json());
            let material_item_unit_ratio = await fetch('./json/import_data/material_item_unit_ratio.json')
                .then((response) => response.json());
            let plan_week_model_data = await fetch('./json/import_data/plan_week_model_data.json')
                .then((response) => response.json());
            return {
                cost_center_material_cfg,cus_group_bom,dinner_type_category_data,dish_bom,dish_key,dish_num_data,material_item,material_item_unit_ratio,plan_week_model_data
            };
        }
    }
    //导入的数据复制到表格
    importPlanModelWeekData(actual_data){
        let {cost_center_material_cfg,cus_group_bom,dinner_type_category_data,dish_bom,dish_key,dish_num_data,material_item,material_item_unit_ratio,plan_week_model_data} = actual_data;

        dinner_type_category_data.forEach(v => {
            v.dinner_type_name = this.dinner_type[v.dinner_type];
        });
        this.index.dinner_type_category = dinner_type_category_data;
        this.index.number_category = dish_num_data;
        this.number_category = toObj(dish_num_data,'id');
        this.dinner_type_category = toObj(dinner_type_category_data,'id');
        this.setLevelScore();
        this.setDishTopCategoryIdsNumbers();

        dish_key.forEach(v => {
            let { id } = v;
            let _cus_group_bom = cus_group_bom.filter(d=>d.dish_key_id == id);
            let _dish_bom = dish_bom.filter(d=>d.dish_key_id == id);
            if(this.dish_key[id]){
                let _i = this.index.dish_key.findIndex(d=>d.id == id);
                this.index.dish_key[_i] = v;
                this.index.cus_group_bom = this.index.cus_group_bom.filter(d=>d.dish_key_id != id);
                this.index.dish_bom = this.index.dish_bom.filter(d=>d.dish_key_id != id);
            }else{
                this.index.dish_key.push(v);
            }
            this.index.cus_group_bom = this.index.cus_group_bom.concat(_cus_group_bom);
            this.index.dish_bom = this.index.dish_bom.concat(_dish_bom);
        })
        material_item.forEach(v=>{
            let { id } = v;
            let _cost_center_material_cfg = cost_center_material_cfg.filter(d=>d.material_id == id);
            let _material_item_unit_ratio = material_item_unit_ratio.filter(d=>d.material_id == id);
            if(this.material_item[id]){
                let _i = this.index.material_item.findIndex(d=>d.id == id);
                this.index.material_item[_i] = v;
                this.index.cost_center_material_cfg = this.index.cost_center_material_cfg.filter(d=>d.material_id != id);
                this.index.material_item_unit_ratio = this.index.material_item_unit_ratio.filter(d=>d.material_id != id);
            }else{
                this.index.material_item.push(v);
            }
            this.index.cost_center_material_cfg = this.index.cost_center_material_cfg.concat(_cost_center_material_cfg);
            this.index.material_item_unit_ratio = this.index.material_item_unit_ratio.concat(_material_item_unit_ratio);
        })
        this.set_cost_center_material_cfg_obj();
        this.update_material_item_by_cost_center_material_cfg();
        this.material_item = toObj(material_item,'id');
        this.update_index_dish_key_cost();
        this.setDishTopCategoryIds();

        let newRowData = getRowData(this,plan_week_model_data);
        this.copyRowData(newRowData,1);
    }
    setSidebarFilter() {
        let sidebarFilter = {};
        // 设置全选
        this.sidebarFilterForm.forEach(v => {
            !sidebarFilter[v.key] && (sidebarFilter[v.key] = []);
            v.children.forEach(item => {
                sidebarFilter[v.key][item.name] = true;
            })
        })
        this.state.sidebarFilter = sidebarFilter;
        this.isCheckAll();
    }

    limitChange(e){
        // console.log();
        //limitCost:'1', //成本限定
        //limitCategory:'1',//食材类别限定
        //limitSave:'1',//生成菜品限定食材
        if(e && e.target && e.target.name =='limitSave'){
            if(this.state.editConfig.limitSave === '1'){
                this.state.editConfig.limitCategory = '1';
            }
            if(this.state.editConfig.limitSave === '0'){
                this.state.editConfig.limitCost = '0';
                this.state.editConfig.limitCategory = '0';
                clearLimitCategoryId(this.planWeekData);
                this.rowData = getRowData(this,this.planWeekData);
                this.gridOptions.api.setRowData(this.rowData);
            }
        }

        this.state.tableConfig.costRange = (this.state.editConfig.limitCost === '1');
        this.setVisible('costRange');
        this.state.tableConfig.category = (this.state.editConfig.limitCategory === '1');
        this.setVisible('category');

        this.refreshCells();
        this.gridOptions.api.redrawRows();
    }

    closeLook(){
        this.state.lookId = '0';
        this.state.lookCompanyId = '0';
    }

    async system_recommend() {
        if (this.state.lookCompanyId === '0' && this.state.lookId === '0') {
            alert('当前公司没有选择数据...');
            return;
        }
        let data_list = [];
        if (this.props.GetSystemRecommendDataList) {
            let model_no = this.ModelNo;
            let week_no = this.state.lookId;
            let name = this.state.lookCompanyId === '0' ? 'current_company' : this.state.lookCompanyId;

            data_list = await this.props.GetSystemRecommendDataList(name, model_no, week_no);
        } else {
            console.log('加载测试数据...');
            data_list = [{
                "dish_top_category_id": 1,
                "dinner_type_id": 14,
                // "dinner_type": "dn2",
                "dish_num_id": 51,
                "day1_key_id": 3094210,
                "day2_key_id": 3138481,
                "day3_key_id": 3093865,
                "day4_key_id": 3138042,
                "day5_key_id": 3139994,
                "day6_key_id": 3094036,
                "day7_key_id": 3094060
            }];
        }
        this.setPlanWeekData(data_list,1);

        console.log('写入当前的模板数据...', data_list);
    }



    // 左侧筛选-检查是否全选
    isCheckAll() {
        let sidebarFilterCheckAll = {};
        for (let key in this.state.sidebarFilter) {
            sidebarFilterCheckAll[key] = true;
            for (let name in this.state.sidebarFilter[key]) {
                if (!this.state.sidebarFilter[key][name]) {
                    sidebarFilterCheckAll[key] = false;
                }
            }
        }
        this.state.sidebarFilterCheckAll = sidebarFilterCheckAll;
    }

    // 左侧-数据筛选
    get sidebarFilterForm() {
        let _arr = [
            {
                name: '餐别',
                key: 'dinner_type_name',
                colKey: 'dinner_type_name',
                children: [
                    // v.dinner_type == 'dn2' ? '午餐' : v.dinner_type == 'dn3' ? '晚餐' : v.dinner_type == 'dn5' ? '夜餐' : '早餐',
                    {name: '中餐', id: 'dn2'},
                    {name: '晚餐', id: 'dn3'},
                    {name: '夜餐', id: 'dn5'},
                    {name: '早餐', id: 'dn1'},
                ]
            },
            {
                name: '类别',
                colKey: 'dish_top_category_name_cn',
                key: 'dish_top_category_name_cn',
                children: []
            }
        ];
        let {dish_top_category} = this.index;
        dish_top_category.forEach(v => {
            v.name = v.name_cn;
        });
        _arr[1].children = dish_top_category;
        return _arr;
    }

    get modelList(){
        let _arr = [];
        this.index.plan_week_model_no_list.forEach(v=>{
            _arr.push(v.plan_week_manual_model)
        });
        _arr.sort((a,b)=>Number(a)-Number(b));
        return _arr;
    }

    get historyList(){
        let _arr = [];
        this.index.plan_week_overall_show.forEach(v=>{
            !_arr.includes(v.week) && _arr.push(v.week)
        });
        return _arr;
    }

    get otherCompany(){
        let _arr = [];
        let {other_company} = this.index;
        for (let company in other_company) {
            let children = [];
            for (let key in other_company[company]) {
                children.push({
                    name:key,
                    isMenu:other_company[company][key] && other_company[company][key].length>0
                })
            }
            _arr.push({
                name:company,
                children:children
            })
        }
        return _arr;
    }

    get recommendList(){
        return ['三周前','去年同期','随机生成']
    }

    get weekDates(){
        let weekDates = [];
        for (let i = 0; i < 6; i++) {
            let start = this.getMonday("s", i);
            let end = this.getMonday("e", i);
            weekDates.push(start+'~'+end)
        }
        return weekDates
    }
    // 查看周菜单
    async GoWeekPlan(e){
        console.log(e.target.dataset.name);
        let week_offset = e.target.dataset.index;
        await this.save();
        if (this.props.GetPlanWeekOverAllShowData) {

            await this.props.GetPlanWeekOverAllShowData(week_offset);
        }

    }
    // 生成周菜单
    async GenerateWeekPlan(e) {
        console.log(e.target.dataset.name);
        let week_offset = e.target.dataset.index;
        let model_no = this.state.modelId;
        await this.save();
        if (this.props.GeneratePlanWeekOverAllShowData) {

            await this.props.GeneratePlanWeekOverAllShowData(model_no, week_offset);
        }
    }

    // 左侧-数据筛选更改
    sidebarFilterChange(e) {
        // console.log('------sidebarFilterChange-------');
        let _model = {};
        for (let key in this.state.sidebarFilter) {
            let colKey = key;
            let obj = this.state.sidebarFilter[key];
            if (key == 'cus_loc_1' || key == 'cus_loc_0') {
                colKey = 'cus_loc_name';
            }
            !_model[colKey] && (
                _model[colKey] = {
                    type: 'startsWith',
                    values: [],
                }
            )
            for (let name in obj) {
                obj[name] && _model[colKey].values.push(name)
            }
        }

        this.gridOptions.api.setFilterModel(_model);
        this.gridOptions.api.onFilterChanged();
        // console.log(this.gridOptions.api.getFilterModel());
        e && this.isCheckAll();
    }

    //左侧-数据筛选更改-全选
    sidebarFilterChangeAll(e) {
        let key = e.target.name;
        let obj = this.state.sidebarFilter[key];
        for (let name in obj) {
            this.state.sidebarFilter[key][name] = this.state.sidebarFilterCheckAll[key];
        }
        this.sidebarFilterChange();
    }

    // 更新菜单表格数据
    updatePlanWeekData(dataArr,noCommand,obj) {
        console.log('-----updatePlanWeekData-----');
        console.log(dataArr);
        if(!Array.isArray(dataArr)){
            dataArr = [dataArr];
        }
        if(!obj){
            obj = {
                newRowDataArr:[],
                dataArr:JSON.parse(JSON.stringify(dataArr)),
                oldPlanWeekArr:[]
            }
        }

        let data = dataArr[0];
        for(let i = 1; i　< 8; i++) {
            let id = data['day'+i+'_key_id'];
            if(this.dishkeyChangeIds[id]){
                // console.log(newItem);
                data['day'+i+'_key_id'] = this.dishkeyChangeIds[id];
            }
        }
        if(data.te_pei_json){
            for(let i = 1; i　< 8; i++) {
                data.te_pei_json['day'+i].forEach((item,index)=>{
                    if(this.dishkeyChangeIds[item]){
                        data.te_pei_json['day'+i][index] = this.dishkeyChangeIds[item];
                    }
                })
            }
        }
        let id = data.id;
        // 更新planWeekData
        let i = this.planWeekData.findIndex(v=>v.id == id);
        let planWeek = this.planWeekData[i];
        let oldPlanWeek = JSON.parse(JSON.stringify(planWeek));
        for (let key in planWeek) {
            planWeek[key] = data[key];
        }
        // 食材类别
        dayKeys.forEach(day=>{
            planWeek[day+'_limit_category_id'] = data[day+'_limit_category_id'];
        });
        //更新rowData
        let rowIndex = this.rowData.findIndex(v=>v.id == id);
        let newRowData = getRowItemData(this,planWeek);
        this.rowData[rowIndex] = newRowData;
        //更新汇总
        this.countRowData = getCountRowData(this.rowData);
        // this.gridOptions.api.getRowNode(id).setData(newRowData);
        // this.refreshCells();

        let newDataArr = dataArr.filter(v=>v.id != id);

        obj.newRowDataArr.push(newRowData);
        obj.oldPlanWeekArr.push(oldPlanWeek);

        // console.log(obj);
        if(newDataArr.length > 0 ){
            this.updatePlanWeekData(newDataArr,noCommand,obj)
        }else{
            this.gridOptions.api.applyTransactionAsync({
                update: obj.newRowDataArr,
            }, (res) => {
                console.log('-------------------------updatePlanWeekData------------------------------');
                this.gridOptions.api.redrawRows();
                this.refreshCells();
            });
            // this.gridOptions.api.applyTransaction({update: obj.newRowDataArr});
            // this.gridOptions.api.redrawRows();
            if(!noCommand){
                this.sentCommand(obj.dataArr,obj.oldPlanWeekArr,'setData')
            }
        }
    }
    getPlanWeekDataById(id){
        let data = this.planWeekData.find(v => {
            return v.id == id
        })
        return data || {};
    }
    // 单元格改变
    onCellValueChanged(params){
        console.log('-----onCellValueChanged----');
        let data = params.data;
        if(params.colDef.field.includes('dish_key_name') && params.colDef.field.includes('day')){
            // field: "day2_dish_key_name"
            let day = params.colDef.field.split('_')[0];
            this.onDishKeyNameChanged(data,day,{name:params.newValue,dish_top_category_id:data.dish_top_category_id})
        }
        if(params.colDef.field.includes('limit_category_name') && params.colDef.field.includes('day')){
            // field: "day1_limit_category_name"
            let day = params.colDef.field.split('_')[0];
            this.onLimitCategoryNameChanged(data,day,{name:params.newValue})
        }

        if(params.colDef.field == 'maxCost' || params.colDef.field == 'minCost'){
            console.log(params.newValue);
            data[params.colDef.field] = Number(data[params.colDef.field]) || 0;
            this.updatePlanWeekData(data);
        }
        if(params.colDef.field == 'dish_num_id_name'){
            console.log(params.newValue);
            let cus_loc_id = 0;
            try {
                cus_loc_id = this.index.cus_loc.find(v=>v.plan_day_cus_name == params.newValue).cus_loc_id;
            }catch (e){}
            data.cus_loc_id = cus_loc_id;
            this.updatePlanWeekData(data);
        }
    }
    // 食材类别改变
    onLimitCategoryNameChanged(data,day,newCate){
        let id = this.getPlanTopCategoryId(newCate.name);
        data[day+'_limit_category_id'] = id;
        if(this.state.editConfig.limitCategory === '1'){
            this.needShowTipCell = {
                id:data.id,
                day:day
            }
        }
        this.updatePlanWeekData(data);
    }
    // 序号/客户是否可编辑
    isDishNumCellEditable(params){
        if(params.data.te_pei_json){
            return true;
        }else{
            return false;
        }
    }
    // 菜品是否可编辑
    isDishCellEditable(params){
        let flag = true;
        let data = params.data;
        if(data.isSpecialGroups){
            let day = params.colDef.field.split('_')[0];
            let teseData = this.planWeekData.find(v=>{
                return v.dish_num_id == data.dish_num_id && v.dinner_type_id == data.dinner_type_id && v.dish_top_category_id == 4;
            })
            flag = !!teseData[day+'_key_id'];
        }
        return flag;
    }

    // 菜品名改变
    onDishKeyNameChanged(data,day,newDish){
        console.log('-----onDishKeyNameChanged----');
        console.log(newDish);
        if(data.te_pei_json){
            let dish_name_arr = [];
            try{
                dish_name_arr = newDish.name.split('/');
                dish_name_arr = dish_name_arr.filter(v=>!!v);
            }catch (e) {}
            console.log(dish_name_arr);
            if(dish_name_arr.length == 0){
                data[day+'_key_id'] = 0;
                data.te_pei_json[day] = [];
            }else{
                let te_pei_json = [];
                dish_name_arr.forEach((v,i)=>{
                    let id = 0;
                    let dish = {name:v};
                    if(i == 0){
                        dish.dish_top_category_id = 4;
                        id = this.getDishKeyIdByName(dish.name,dish.dish_top_category_id);
                    }else{
                        let te_pei = this.formatterTePeiStrToObj(v);
                        id = te_pei.id;
                        dish.dish_top_category_id = te_pei.dish_top_category_id;
                    }
                    if(!id){
                        dish.name = formatDishKeyName(dish.name);
                        // 没有菜品
                        id = this.addDish(dish);
                    }
                    if(i == 0){
                        data[day+'_key_id'] = id;
                    }else{
                        te_pei_json.push(id);
                    }
                })
                if(!data[day+'_key_id']){
                    data.te_pei_json[day] = [];
                }else{
                    data.te_pei_json[day] = te_pei_json;
                }

            }
            if(this.state.editConfig.limitCategory != '1'){
                data[day + '_limit_category_id'] = 0;
            }
            this.needShowTipCell = {
                id:data.id,
                day:day
            };
            this.updatePlanWeekData(data);
            return;
        }
        // 修改菜品
        newDish.name = this.formatterTePeiStrToObj(newDish.name).name;
        newDish.name = formatDishKeyName(newDish.name);
        // console.log(newDish.name);
        let id = this.getDishKeyId(newDish.name,newDish.dish_top_category_id);
        if(!id){
            // 没有菜品
            id = this.addDish(newDish);
        }
        if(data[day+'_key_id'] == id){
            //没有修改
            return false;
        }
        data[day+'_key_id'] = id;
        if(this.state.editConfig.limitCategory != '1'){
            data[day + '_limit_category_id'] = 0;
        }
        this.needShowTipCell = {
            id:data.id,
            day:day
        };
        if(id == 0 && data.sales_type == "special" && data.dish_top_category_id == 4){ //如果特色清空 配菜也清空
            this.clearSpecialDish(data,day);
        }else{
            this.updatePlanWeekData(data);
        }
    }
    // 清空特色组配菜与特色
    clearSpecialDish(data,day){
        let specials = this.rowData.filter(v=> v.sales_type == "special" && v.dish_num_id == data.dish_num_id && v.dinner_type_id == data.dinner_type_id);
        specials.forEach(v=>{
            v[day+'_key_id'] = 0;
        })
        this.updatePlanWeekData(specials);
    }
    undoCommand(){
        this.isUndoRedoCommand=true;
        this.commander.undo();
        this.isUndoRedoCommand=false;
    }
    redoCommand(){
        this.isUndoRedoCommand=true;
        this.commander.redo();
        this.isUndoRedoCommand=false;
    }
    sentCommand(newValue,oldValue,tag){
        if(this.isUndoRedoCommand) return;
        if(!tag) return;
        let _this = this;
        let updateCommand = new baseCommand();
        updateCommand.execute = function(){
            //这里执行变更导致的结果
            // console.log('----execute---');
        }

        let options={};
        // options.source=$(this)
        options.newValue = newValue;
        options.oldValue = oldValue;
        updateCommand.setOptions(options);
        switch(tag){
            case 'setData'://更新行数据
                updateCommand.undo = function(){
                    _this.updatePlanWeekData(options.oldValue,1)
                }
                updateCommand.redo = function(){
                    _this.updatePlanWeekData(options.newValue,1)
                }
                break;
            case 'addRow'://更新行数据
                updateCommand.undo = function(){
                    _this.showRows(options.oldValue,0,1)
                }
                updateCommand.redo = function(){
                    _this.showRows(options.oldValue,1,1)
                }
                break;
            case 'removeRow'://更新行数据
                updateCommand.undo = function(){
                    _this.showRows(options.oldValue,1,1)
                }
                updateCommand.redo = function(){
                    _this.showRows(options.oldValue,0,1)
                }
                break;
            case 'setRowData'://更新表格数据
                updateCommand.undo = function(){
                    _this.setPlanWeekData(options.oldValue)
                }
                updateCommand.redo = function(){
                    _this.setPlanWeekData(options.newValue)
                }
                break;
            default:
        }

        //在管理器中执行
        this.commander.executeCommand(updateCommand);
    }
    // 获取菜品ID
    getDishKeyId(name,dish_top_category_id){
        if(!name || !dish_top_category_id){
            return 0
        }
        let dish = this.index.dish_key.find(v=>v.name == name && v.dish_top_category_id == dish_top_category_id) || {};
        let id = dish.id || 0;
        return id
    }
    //特色配菜的复制 可能没有dish_top_category_id
    getDishKeyIdByName(name,dish_top_category_id){
        if(!name){
            return 0
        }
        let dish = {};
        if(!dish_top_category_id){
            dish = this.index.dish_key.find(v=>v.name == name) || {};
        }else{
            dish = this.index.dish_key.find(v=>v.name == name && v.dish_top_category_id == dish_top_category_id) || {};
        }
        let id = dish.id || 0;
        return id
    }
    //isAdd 自动新增
    getDishNumId(numCate,isAdd){
        if(!numCate){
            return 0
        }
        if(!numCate.dish_top_category_id){
            return 0
        }
        let num = this.index.number_category.find(v=>v.dish_top_category_id == numCate.dish_top_category_id && v.ctg1_no == numCate.ctg1_no) || {};
        let id = num.id || 0;
        if(isAdd && !id){
            let arr = this.dishTopCategoryIdsNumbers[numCate.dish_top_category_id].children||[];
            let last;
            if(arr.length == 0){
                last = {ctg1_no:0};//没有这个类别的序号
            }else{
                arr.sort((a,b)=>{return a.ctg1_no-b.ctg1_no});
                last = arr[arr.length-1];
            }

            let newNumCate = JSON.parse(JSON.stringify(numCate));
            newNumCate.ctg1_no = last.ctg1_no + 1;
            newNumCate.name = this.dishTopCategoryIdsNumbers[numCate.dish_top_category_id].name + newNumCate.ctg1_no;
            // newNumCate.id = "virtual_" + (this.creatNumberCategoryList.length + 1);
            newNumCate.id = add_number_category_id();
            this.creatNumberCategoryList.push(newNumCate);
            this.index.number_category.push(newNumCate);
            this.number_category = toObj(this.index.number_category,'id');
            this.setDishTopCategoryIdsNumbers();
            this.setLevelScore();
            id = newNumCate.id;
        }
        return id
    }
    addNumberCategory(dish_top_category_id){
        console.log(dish_top_category_id);
        let arr = this.dishTopCategoryIdsNumbers[dish_top_category_id].children||[];
        arr.sort((a,b)=>{return a.ctg1_no-b.ctg1_no});
        let last = arr[arr.length-1];
        let newNumCate = {
            id:add_number_category_id(),
            dish_top_category_id:dish_top_category_id,
            ctg1_no:last.ctg1_no + 1,
        };
        newNumCate.name = this.dishTopCategoryIdsNumbers[dish_top_category_id].name + newNumCate.ctg1_no;
        newNumCate.no = newNumCate.ctg1_no;
        this.creatNumberCategoryList.push(newNumCate);
        this.index.number_category.push(newNumCate);
        this.number_category = toObj(this.index.number_category,'id');
        this.setDishTopCategoryIdsNumbers();
        this.setLevelScore();
        return newNumCate.id
    }
    getDinnerTypeCategoryId(item,isAdd){
        let dinner_type_category = this.index.dinner_type_category.find(v=>v.name == item.name && v.dinner_type == item.dinner_type);
        if(dinner_type_category){
            return dinner_type_category.id;
        }
        if(isAdd){
            return this.addDinnerTypeCategory(item);
        }else{
            return 0;
        }
    }
    addDinnerTypeCategory(item){
        let arr = this.index.dinner_type_category.filter(v=>v.dinner_type == item.dinner_type);
        let last = arr[arr.length-1];
        let dinner_type_category = {
            dinner_type:item.dinner_type,
            dt_no:last.dt_no+1,
            id:add_dinner_type_id(),
            name:item.name,
            dinner_type_name:this.dinner_type[item.dinner_type]
        };
        this.index.dinner_type_category.push(dinner_type_category);
        this.index.dinner_type_category.sort((a,b)=>{return dinnerTypeCategoryComparator(a,b)});
        this.dinner_type_category = toObj(this.index.dinner_type_category,'id');
        this.creatDinnerTypeCategoryList.push(dinner_type_category);
        this.setLevelScore();
        return dinner_type_category.id
    }
    getPlanTopCategoryId(name){
        if(!name){
            return 0
        }
        let category = this.index.plan_top_category.find(v=>v.name == name) || {};
        let id = category.id || 0;
        return id
    }

    SetAGOptions() {
        let _this = this;
        console.log('-----SetAGOptions----');
        this.gridOptions = Object.assign({}, init_grid_options(), {
            columnDefs: col(_this),
            rowData: this.rowData,
            suppressRowClickSelection: true,
            rowHeight:28,
            getRowHeight:(params)=>{
                let is_te_pei = !!params.data && params.data.te_pei_json;
                if(is_te_pei){
                    return 43
                }else{
                    return 28
                }

            },
            headerHeight:22,
            context: {
                owl_widget: this
            },
            onCellValueChanged: (e) => {
                // console.log(e);
                _this.onCellValueChanged(e);
            },
            getContextMenuItems: (e) => {
                return _this.setAGMenus(e);
            },
            getRowId: (params) => {
                return params.data.id;
            },
            rowDragManaged: true,
            onGridReady: function (params) {
                let defaultSortModel = [
                    { colId: 'dinner_type_category_name', sort: 'asc', sortIndex: 0 },
                    { colId: 'LevelScore', sort: 'asc', sortIndex: 0 },
                    // { colId: 'sequence_tag', sort: 'asc', sortIndex: 0 },
                    // { colId: 'dish_top_category_id', sort: 'asc', sortIndex: 1 },
                    // { colId: 'dish_num_id', sort: 'asc', sortIndex: 2 }
                    // { colId: 'dish_num_id_name', sort: 'asc', sortIndex: 2 }
                ];
                params.columnApi.applyColumnState({ state: defaultSortModel });
            },
            enableRangeSelection:false,
            getRowStyle: params => {
                if (params && params.node && params.node.data && params.node.data.sales_type == 'special' && params.node.data.dish_top_category_id != 4) { //特色组配菜背景色
                    return { background: '#f4f6fa' };
                }
            },
            columnTypes:{
                editableColumn:{
                    editable: (params) => {
                        if(params.colDef.field.endsWith('dish_key_name')){
                            return _this.isDishCellEditable(params);
                        }
                        if(params.colDef.field.endsWith('dish_num_id_name')){
                            return _this.isDishNumCellEditable(params);
                        }

                    },
                }
            },
            onFilterChanged:(params) => {
                // console.log('-------onFilterChanged----------');
                _this.gridOptions.api.redrawRows();
            },
            suppressRowTransform:true,
            onCellEditingStarted:async (event)=>{
                if(!_this.state.LoadSecDataFlag){
                    await _this.LoadSecData()
                }
            },
            processDataFromClipboard: _this.processDataFromClipboard.bind(_this)
        })
    }
    processDataFromClipboard(params){
        console.log(params);
        let data = this.checkClipboardData(params);
        return data;
    }
    checkClipboardData(params){
        let data = params.data;
        if(data[data.length-1].length == 1 && data[data.length-1][0] == ''){
            data = data.filter((v,i)=> i+1 != data.length);//从excel复制时会多一行
        }
        let length = data.length;
        if(length === 0){
            return data
        }
        let focusedCell = params.api.getFocusedCell();
        let rowIndex = focusedCell.rowIndex;
        let colId = focusedCell.column.colId;
        if(colId == 'dish_top_category_name' || colId.endsWith('_dish_key_name')){
            let rowData = [];
            let colIds = ['dish_top_category_name'];
            for(let i = 1; i　< 8; i++) {
                colIds.push(`day${i}_dish_key_name`);
            }
            params.api.forEachNode(function (node) {
                let _rowIndex = node.rowIndex;
                if(_rowIndex>(rowIndex-1) && _rowIndex< (rowIndex+length)){
                    if(node.group){
                        length++
                    }else{
                        rowData.push(node.data)
                    }
                }
            });
            let flag = false;
            let error = '';
            let currIndex = colIds.findIndex(v=>v == colId);
            rowData.forEach((v,i)=>{
                // if(flag){
                //     return;
                // }
                data[i].forEach((t,index)=>{
                    let t_col = colIds[currIndex+index];
                    if(!t_col){
                        return;
                    }
                    // if(t_col == 'dish_top_category_name' && !v.te_pei_json){
                    //     flag = true;
                    //     error = '非特色的餐别序号不允许修改。'
                    // }
                    if(t.includes('/') && !v.te_pei_json && t_col.endsWith('_dish_key_name')){
                        flag = true;
                        error = '非特色的菜品名不允许包含分隔符“/”，已将“/”替换为“~”。'
                        data[i][index] = formatDishKeyName(t.replace(/\//g,'~'));
                        // console.log(data[i][index]);
                    }
                })
            })

            if(flag){
                // data = [];
                this.state.toastData = {
                    msg:error
                };
                this.state.toastOpen = true;
            }
        }
        return data;
    }

    getRowSpan(params){

        let span = 1;
        let data = params.data;
        let filterArr = [];
        let obj = this.state.sidebarFilter['dish_top_category_name_cn'];
        if(data.dish_top_category_id == 4){
            return 1;
        }
        if(data.sales_type == 'kuai'){
            params.api.forEachNode(v=>{
                if (v.data == undefined) return;
                if(this.state.sidebarFilter.dish_top_category_name_cn[v.data.dish_top_category_name_cn] && v.data.dinner_type_id == data.dinner_type_id && v.data.dish_top_category_id == data.dish_top_category_id && v.data.sales_type == data.sales_type){
                    filterArr.push(v.data);
                }
            })
            // filterArr = this.rowData.filter(v=>v.dinner_type == data.dinner_type && v.dish_top_category_id == data.dish_top_category_id && v.sales_type == data.sales_type);
        }else{
            params.api.forEachNode(v=>{
                if (v.data == undefined) return;
                if(this.state.sidebarFilter.dish_top_category_name_cn[v.data.dish_top_category_name_cn] && v.data.dinner_type_id == data.dinner_type_id && v.data.sales_type == data.sales_type){
                    filterArr.push(v.data);
                }
            })
            // filterArr = this.rowData.filter(v=>v.dinner_type == data.dinner_type && v.sales_type == data.sales_type);
        }
        filterArr.sort((a,b)=>{return a.LevelScore-b.LevelScore});
        if(data.id == filterArr[0].id){
            span = filterArr.length;
        }
        return span;
    }

    // 右键菜单
    setAGMenus(e) {
        // console.log('-------setAGMenus-------');
        // console.log(e);
        let node = e.node || {};
        // console.log(node.rowIndex);
        let _this = this;
        let field = '';
        let data = {};
        let addRowTeseMenu = [];
        let teseData = [];
        if(e.column && e.column.colDef){
            field = e.column.colDef.field;
        }
        if(node.data){
            data = node.data;
            teseData = this.planWeekData.filter(v=>{
                return v.dinner_type_id == data.dinner_type_id && v.dish_top_category_id === 4 && !v.isDeleted;
            });
        }
        if(teseData.length > 0){
            teseData.forEach(v=>{
                let length = addRowTeseMenu.push({
                    name:'新增：'+ _this.number_category[v.dish_num_id].name + ' - 配菜',
                    subMenu:[]
                })
                _this.sidebarFilterForm[1].children.forEach(item => {
                    if(item.id != 4){
                        addRowTeseMenu[length-1].subMenu.push({
                            name: item.name,
                            disabled: !this.state.sidebarFilter.dish_top_category_name_cn[item.name],
                            action:()=>{
                                _this.addRow(node,{},item,_this.number_category[v.dish_num_id]);
                            }
                        })
                    }
                })
            })
            addRowTeseMenu.push('separator');
        }
        let addRowSubMenu = [];
        this.index.dinner_type_category.forEach(dn=>{
            let v = {
                name:`新增一行：${dn.name}`,
            };
            v.subMenu = [];
            v.disabled = !this.state.sidebarFilter.dinner_type_name[dn.dinner_type_name];
            _this.sidebarFilterForm[1].children.forEach(item => {
                let subMenuItem = {
                    name: item.name,
                    disabled: !this.state.sidebarFilter.dish_top_category_name_cn[item.name],
                    // action: ()=>{},
                };
                if(item.id == 4){
                    subMenuItem.subMenu = this.index.cus_loc.map(cus=>{
                        return {
                            name:cus.plan_day_cus_name,
                            action:()=>{
                                _this.addTePeiRow(node,{
                                    dinner_type_id:dn.id,
                                    cus_loc_id:cus.cus_loc_id
                                });
                            }
                        }
                    })
                }else{
                    subMenuItem.action = () =>{
                        _this.addRow(node,{
                            dinner_type:dn.dinner_type,
                            dinner_type_name:dn.dinner_type_name,
                            id:dn.id,
                            name:dn.name
                        },item);
                    }
                }
                v.subMenu.push(subMenuItem)
            });
            addRowSubMenu.push(v);
        });
        let menus = [];
        // 修改菜品
        let editable = e.column && e.column.colDef && e.column.colDef.editable && e.column.colDef.editable({
            ...e.column,data:e.node.data
        });
        // e.column.colDef.editable
        if(editable){
            menus.push({
                name: '修改',
                action: () => {
                    let colKey = e.column.colId;
                    _this.startEditingCell(node.rowIndex,colKey);
                },
            })
            if(e.value != '' && e.column.colDef.field.includes('dish_key_name')){
                let day = e.column.colDef.field.split('_')[0];
                let dish_key_id = node.data[day+'_key_id'];
                if(dish_key_id){
                    menus.push({
                        name: '菜品详情：'+_this.dish_key[dish_key_id].name,
                        action: () => {
                            _this.editDish(dish_key_id);
                        },
                    })
                }

                if(node.data.te_pei_json){
                    node.data.te_pei_json[day].forEach(dish_key_id=>{
                        if(_this.dish_key[dish_key_id].dish_top_category_id){
                            menus.push({
                                name: '菜品详情：'+_this.dish_key[dish_key_id].name,
                                action: () => {
                                    _this.editDish(dish_key_id);
                                },
                            })
                        }else{
                            let _subMenu = _this.index.dish_top_category.map(v=>{
                                return {
                                    name:v.name_cn,
                                    action:()=>{
                                        _this.setDishTopCategoryId(dish_key_id,v.id);
                                    }
                                }
                            });
                            _subMenu = _subMenu.filter(v=>v.name!='特色');
                            menus.push({
                                name: '设置类别：'+_this.dish_key[dish_key_id].name,
                                subMenu:_subMenu
                            })
                        }
                    })

                }
            }
            menus.push('separator');
        }

        if(field != 'dish_top_category_name_cn' && node.data){
            let addRowData = {
                dish_num:{}
            };
            if(data.isSpecialGroups){
                addRowData.dish_num = {
                    id:data.dish_num_id
                }
            }
            if(!data.te_pei_json){
                menus.push({
                    name: '向上新增一行',
                    action: () => {
                        _this.addRowByOrder(node,'up');
                    },
                })
                menus.push({
                    name: '向下新增一行',
                    action: () => {
                        _this.addRowByOrder(node,'down');
                    },
                })
            }else{
                menus.push({
                    name: '向上新增一行',
                    action: () => {
                        _this.addTePeiRowByOrder(node,'up');
                    },
                })
                menus.push({
                    name: '向下新增一行',
                    action: () => {
                        _this.addTePeiRowByOrder(node,'down');
                    },
                })
            }
            menus.push({
                name: '删除本行',
                action: () => {
                    _this.removeRow(node.data);
                },
                cssClasses: ['text-danger'],
            })
            menus.push('separator');
        }

        menus = menus.concat(addRowTeseMenu,addRowSubMenu);
        return menus;

    }
    setDishTopCategoryId(dish_key_id,dish_top_category_id){
        let i = this.index.dish_key.findIndex(v=>v.id == dish_key_id);
        this.index.dish_key[i].dish_top_category_id = dish_top_category_id;
        let _i = this.creatDishList.findIndex(v=>v.id == dish_key_id);
        this.creatDishList[_i].dish_top_category_id = dish_top_category_id;
        this.dish_key = toObj(this.index.dish_key,'id');
        this.gridOptions.api.redrawRows();
    }

    startEditingCell(rowIndex,colKey,charPress){
        this.gridOptions.api.startEditingCell({
            rowIndex: rowIndex,
            colKey: colKey,
            // set to 'top', 'bottom' or undefined
            // rowPinned: pinned,
            // key: key,
            charPress: charPress ||'',
        });
    }
    // 新增行 向上新增 或向下新增
    addRowByOrder(node,upOrDown){
        let _this = this;
        let data = node.data;
        _this.addRowMaxId++;
        let newItem = {
            id: _this.addRowMaxId,
            day1_key_id: 0,
            day2_key_id: 0,
            day3_key_id: 0,
            day4_key_id: 0,
            day5_key_id: 0,
            day6_key_id: 0,
            day7_key_id: 0,
            dinner_type_id:data.dinner_type_id,
            // dinner_type: data.dinner_type,
            dish_top_category_id: data.dish_top_category_id,
            dish_num_id: data.dish_num_id,
            sales_type:data.sales_type,
            LevelScore:upOrDown == 'up'?data.LevelScore-1:data.LevelScore+1
        };
        let planWeekData = JSON.parse(JSON.stringify(_this.planWeekData));
        planWeekData.push(newItem);
        let newPlanWeekData = this.updateDishNumIds(planWeekData);
        this.setPlanWeekData(newPlanWeekData,1);
    }
    // 新增行 没有dinner就用当前行的dinner_type，没有dish_top_category就用当前行的dish_top_category_id
    addRow(node, dinner = {}, dish_top_category = {},dish_num = {}) {
        console.log('---addRow--------');
        // console.log(dinner);
        // console.log(dish_top_category);
        let _this = this;

        let dinner_type_id = dinner.id || node.data.dinner_type_id;
        // let dinner_type = dinner.dinner_type || node.data.dinner_type;
        let dish_top_category_id = dish_top_category.id || node.data.dish_top_category_id;
        let dish_num_id = dish_num.id;
        let isSpecial = !!(dish_top_category_id == 4 || dish_num_id);
        let num_and_top_category = this.countRowData.num_and_top_category;
        if(!dish_num_id){
            let arr = num_and_top_category[dinner_type_id] && num_and_top_category[dinner_type_id].filter(v=>v.includes('|'+dish_top_category_id)) || [];
            // console.log(arr);
            let d = this.dishTopCategoryIdsNumbers[dish_top_category_id].children.find(v=>{
                return !arr.includes(v.id+'|'+dish_top_category_id)
            });
            if(!d){
                dish_num_id = this.getDishNumId({dish_top_category_id:dish_top_category_id},1);
                // _this.state.toastData.msg = '没有可新增的类别序号';
                // _this.state.toastOpen = true;
                // return false;
            }else{
                dish_num_id = d.id;
            }
        }
        // console.log(dinner_type_id);
        // console.log(dish_top_category_id);
        _this.addRowMaxId++;
        let newItem = {
            id: _this.addRowMaxId,
            day1_key_id: 0,
            day2_key_id: 0,
            day3_key_id: 0,
            day4_key_id: 0,
            day5_key_id: 0,
            day6_key_id: 0,
            day7_key_id: 0,
            dinner_type_id:dinner_type_id,
            // dinner_type: dinner_type,
            dish_top_category_id: Number(dish_top_category_id),
            dish_num_id: Number(dish_num_id) || dish_num_id,
            sales_type:isSpecial?'special':'kuai',
            minCost:0,
            maxCost:2,
            // sequence_tag:0,
        };
        newItem.LevelScore = this.getLevelScore(newItem);
        this.planWeekData.push(newItem);
        let newRowData = getRowItemData(this,newItem);
        this.showRows([newRowData],1);
    }
    addTePeiRow(node, data){
        // console.log(data);
        let sequence_tag = 0;
        let _this = this;
        let rows = this.planWeekData.filter(v=>!v.isDeleted && v.dinner_type_id == data.dinner_type_id && v.te_pei_json);
        if(rows.length>0){
            rows.sort((a,b)=>{return a.sequence_tag-b.sequence_tag});
            sequence_tag = rows[rows.length-1].sequence_tag+1;
        }
        _this.addRowMaxId++;
        let newItem = {
            id: _this.addRowMaxId,
            day1_key_id: 0,
            day2_key_id: 0,
            day3_key_id: 0,
            day4_key_id: 0,
            day5_key_id: 0,
            day6_key_id: 0,
            day7_key_id: 0,
            dinner_type_id:data.dinner_type_id,
            cus_loc_id:data.cus_loc_id,
            minCost:0,
            maxCost:2,
            te_pei_json:{
                day1:[],
                day2:[],
                day3:[],
                day4:[],
                day5:[],
                day6:[],
                day7:[],
            },
            sequence_tag:sequence_tag,
        };
        newItem.LevelScore = this.getLevelScore(newItem);
        // console.log(newItem.LevelScore);
        this.planWeekData.push(newItem);
        let newRowData = getRowItemData(this,newItem);
        this.showRows([newRowData],1);
    }
    // 新增行 向上新增 或向下新增
    addTePeiRowByOrder(node,upOrDown){
        let _this = this;
        let data = node.data;
        _this.addRowMaxId++;
        let newItem = {
            id: _this.addRowMaxId,
            day1_key_id: 0,
            day2_key_id: 0,
            day3_key_id: 0,
            day4_key_id: 0,
            day5_key_id: 0,
            day6_key_id: 0,
            day7_key_id: 0,
            dinner_type_id:data.dinner_type_id,
            cus_loc_id:data.cus_loc_id,
            minCost:0,
            maxCost:2,
            te_pei_json:{
                day1:[],
                day2:[],
                day3:[],
                day4:[],
                day5:[],
                day6:[],
                day7:[],
            },
            // sequence_tag:sequence_tag,
            LevelScore:upOrDown == 'up'?data.LevelScore-1:data.LevelScore+1
        };
        let planWeekData = JSON.parse(JSON.stringify(_this.planWeekData));
        planWeekData.push(newItem);
        let newPlanWeekData = this.updateSequenceTag(planWeekData);
        this.setPlanWeekData(newPlanWeekData,1);
    }
    updateSequenceTag(planWeekData){
        let _this = this;
        let numObj = {};
        let newPlanWeekData = JSON.parse(JSON.stringify(planWeekData));
        newPlanWeekData.sort((a,b)=>{return a.LevelScore-b.LevelScore});
        newPlanWeekData.forEach(v=>{
            if(v.isDeleted){
                return;
            }
            if(!v.te_pei_json){
                return;
            }
            !numObj[v.dinner_type_id] && (numObj[v.dinner_type_id] = 0);
            numObj[v.dinner_type_id]++;
            v.sequence_tag = numObj[v.dinner_type_id];
        })
        return newPlanWeekData;
    }


    // 删除行
    removeRow(data) {
        // console.log('removeRow');
        let _this = this;
        let removeRowData = [];
        if(data.sales_type === 'special' && !data.isSpecialGroups){
            // 特色的配菜也删除
            _this.rowData.forEach(v=>{
                if(v.dish_num_id == data.dish_num_id && v.dinner_type_id == data.dinner_type_id){
                    removeRowData.push(v);
                }
            })
        }else{
            removeRowData.push(data)
        }
        // this.showRows(removeRowData,0);
        let ids = removeRowData.map(item => item.id);
        let planWeekData = JSON.parse(JSON.stringify(_this.planWeekData));
        planWeekData.forEach(v => {
            if(ids.includes(v.id)){
                v.isDeleted = 1
            }
        });
        let newPlanWeekData = this.updateDishNumIds(planWeekData);
        // console.log(newPlanWeekData);
        this.setPlanWeekData(newPlanWeekData,1);
    }
    // 显示行 或 删除行
    showRows(rows,isShow,noCommand){
        console.log(`-------${isShow?'显示行':'删除行'}------`);
        let _this = this;
        let rowData = [];
        let ids = rows.map(item => item.id);
        _this.planWeekData.forEach(v => {
            if(ids.includes(v.id)){
                v.isDeleted = !isShow
            }
        });
        if(isShow){
            this.gridOptions.api.applyTransactionAsync({
                add: rows,
            }, (res) => {
                _this.gridOptions.api.redrawRows();
                _this.refreshCells();
            });
            rowData = _this.rowData.concat(rows);
        }else{
            this.gridOptions.api.applyTransactionAsync({
                remove: rows,
            }, (res) => {
                _this.gridOptions.api.redrawRows();
                _this.refreshCells();
            });
            rowData = _this.rowData.filter(v=>!ids.includes(v.id));
        }
        _this.rowData = rowData;
        _this.countRowData = getCountRowData(_this.rowData);

        if(!noCommand){
            isShow && this.sentCommand(rows,rows,'addRow');
            !isShow && this.sentCommand(rows,rows,'removeRow');
        }
    }
    // 更新dish_num_id依次补齐缺漏的序号1,2,3
    updateDishNumIds(planWeekData){
        let newPlanWeekData = JSON.parse(JSON.stringify(planWeekData));
        let dish_num_ids = {};//待使用的dish_num_id
        let old_dish_num_ids = {};//更改的dish_num_id
        // console.log(this.dishTopCategoryIdsNumbers);

        let dinner_type_ids = this.index.dinner_type_category.map(v=>v.id);
        dinner_type_ids.forEach(dinner_type_id=>{
            dish_num_ids[dinner_type_id] = {};
            old_dish_num_ids[dinner_type_id]={};
            for(let dish_top_category_id in this.dishTopCategoryIdsNumbers){
                let arr = this.dishTopCategoryIdsNumbers[dish_top_category_id].children||[];
                dish_num_ids[dinner_type_id][dish_top_category_id] =JSON.parse(JSON.stringify(arr.sort((a,b)=>{return a.ctg1_no-b.ctg1_no})));
            }
        });
        // console.log(dish_num_ids);
        newPlanWeekData.sort((a,b)=>{return a.LevelScore-b.LevelScore});
        newPlanWeekData.forEach(v=>{
            if(v.isDeleted){
                return;
            }
            if(v.sales_type == 'special' && v.dish_top_category_id != 4){
                return;
            }
            if(v.te_pei_json){
                v.dish_num_id = 0;
                return;
            }
            let old_dish_num_id = v.dish_num_id;
            try{
                v.dish_num_id = dish_num_ids[v.dinner_type_id][v.dish_top_category_id][0].id;
                dish_num_ids[v.dinner_type_id][v.dish_top_category_id].splice(0, 1);
            }catch (e) {
                v.dish_num_id = this.addNumberCategory(v.dish_top_category_id);
            }
            old_dish_num_ids[v.dinner_type_id][old_dish_num_id] = v.dish_num_id;
        });
        newPlanWeekData.forEach(v=>{
            if(v.isDeleted){
                return;
            }
            if(v.sales_type == 'special' && v.dish_top_category_id != 4){
                v.dish_num_id = old_dish_num_ids[v.dinner_type_id][v.dish_num_id];
            }
        });
        return newPlanWeekData;
    }


    RenderAG() {
        let _this = this;
        this.SetAGOptions();
        this.agGrid = new agGrid.Grid(this.myGrid_ref.el, this.gridOptions);
        this.limitChange();
        // console.log('-----RenderAG-------');
        document.addEventListener('dragend', function(ev){
            // console.log('--------dragend --------');
            if(_this.lastDrop){
                _this.lastDrop.removeAttribute('over');
                _this.lastDrop.removeAttribute('candrop');
                _this.lastDrop.removeAttribute('repeat');
                _this.lastDrop.removeAttribute('same');
            }
        })

        new bootstrap.Tooltip('.infoTip');
        new bootstrap.Tooltip('#copy');
        // new bootstrap.Tooltip('#system_recommend');
        new bootstrap.Tooltip('.clear');
        new bootstrap.Tooltip('.resume');
        new bootstrap.Tooltip('.rightTip');


        this.commander.changed = function(){
            if(_this.commander.canRedo()){
                // console.log('----canRedo-----');
                _this.state.canRedo = true;
            }else{
                _this.state.canRedo = false;
                // console.log('----canRedo---else--');
            }
            if(_this.commander.canUndo()){
                // console.log('----canUndo---');
                _this.state.canUndo = true;
            }else{
                // console.log('----canUndo--else----');
                _this.state.canUndo = false;
            }
        }
    }

    async openCreatMaterialModal(obj, callback) {
        if(!this.state.LoadSecDataFlag){
            await this.LoadSecData()
        }
        console.log('----openCreatMaterialModal----');
        !obj && (obj = {});
        this.state.CreatMaterialModalData = {...obj, callback};
        this.state.CreatMaterialModalEdit = obj.id ? true : false;
        this.state.CreatMaterialModalOpen = true;
    }
    openUnitRatioModal(data, callback) {
        this.state.UnitRatioModalData = {...data, callback};
        this.state.UnitRatioModalOpen = true;
    }

    // 菜品详情  data行数据
    async editDish_bak(id,data){
        await this.save();
        console.log("跳转菜品详情 id:",id);

        if (this.props.PlanWeekModelOverallShowDishKeyBom) {
            await this.props.PlanWeekModelOverallShowDishKeyBom(id);
        }
    }
    async editDish(id, callback) {
        if(!this.state.LoadSecDataFlag){
            await this.LoadSecData()
        }
        // console.log('editDish');

        id = formatId(id);
        // let dish = this.index.dish_key.find(v => v.id == id) || {};
        // console.log(dish);
        if (this.state.CreatDishModalOpen) {
            this.state.CreatDishModalOpen = false;
        }
        this.state.CreatDishData = {id};
        this.state.CreatDishModalEdit = true;
        this.state.CreatDishData.callback = callback;
        this.state.CreatDishModalOpen = true;
    }
    // 创建菜品
    async creatDish(dish,callback) {
        if(!this.state.LoadSecDataFlag){
            await this.LoadSecData()
        }
        // console.log(d);
        if (this.state.CreatDishModalOpen) {
            this.state.CreatDishModalOpen = false;
        }
        this.state.CreatDishData = dish;
        this.state.CreatDishModalEdit = false;
        this.state.CreatDishData.callback = callback;
        this.state.CreatDishModalOpen = true;
    }
    // 更新菜品
    updataDish(dish,id){
        delete dish.id;
        let i = this.index.dish_key.findIndex(v=> v.id + '' === id + '');
        this.index.dish_key[i] = Object.assign(this.index.dish_key[i], dish);
        let index = this.creatDishList.findIndex(v=> v.id + '' === id + '');
        if(index!=-1){
            this.creatDishList[index] = Object.assign(this.creatDishList[index], dish);
        }
        this.dish_key = toObj(this.index.dish_key,'id');
    }
    // 快捷新增 返回id
    addDish(newDish) {
        if(!newDish || !newDish.name || newDish.name.trim()==''){ return 0 };
        // newDish.id = "virtual_" + (this.creatDishList.length + 1);
        newDish.id = add_dish_key_id();
        newDish.is_confirmed = false;
        newDish.cooking_method_id = newDish.cooking_method_id || this.index.cooking_category[0].id;
        newDish.dish_cost = 0;
        this.creatDishList.push(newDish);
        this.index.dish_key.push(newDish);
        this.dish_key = toObj(this.index.dish_key,'id');
        console.log(this.creatDishList);
        return newDish.id;
    }
    // 异步新增/编辑 弹窗-确定
    async addDishAsync(newDish, isEdit,isChangedName) {
        if (!newDish || newDish.name.trim() == '') {
            return 0
        }

        // console.log(isEdit);

        let res;
        if (this.props.UpdateDishKeyVals) {
            res = await this.props.UpdateDishKeyVals(newDish);
            // let dish_key_obj_res = {
            //     id: 333,
            //     dish_bom_id_list: [
            //         1,
            //         2,
            //         3,
            //     ]
            // }
        } else {
            res = await this.request(newDish);
        }
        let { cus_group_dish_bom_list } = res;

        let isSetPlanWeekData = false;

        let isChangeId = false;
        let oldId = newDish.id;
        if(res.id != newDish.id){
            isChangeId = true;
            isSetPlanWeekData = true;
            this.dishkeyChangeIds[oldId] = res.id;
            this.creatDishList = this.creatDishList.filter(v=>v.id != oldId);
            this.index.dish_key = this.index.dish_key.filter(v=>v.id != oldId);
            this.dish_key = toObj(this.index.dish_key, 'id');
        }


        Object.assign(newDish, {
            id: res.id,
            is_fish:res.is_fish,
            is_organ:res.is_organ,
            is_semi_finished:res.is_semi_finished,
            spicy:res.spicy,
            is_cow:res.is_cow,
            is_dark_goose:res.is_dark_goose
        });
        // newDish.id = res.id;
        // console.log(res);
        if (isEdit) {
            let i = this.index.dish_key.findIndex(v => {
                return res.id === v.id
            });
            if(i == -1){
                this.index.dish_key.push(newDish);
                this.dish_key = toObj(this.index.dish_key, 'id');
            }else{
                this.index.dish_key[i] = Object.assign(this.index.dish_key[i], newDish);
                this.dish_key = toObj(this.index.dish_key, 'id');
            }
        } else {
            this.index.dish_key.push(newDish);
            this.dish_key = toObj(this.index.dish_key, 'id');
        }
        let cus_group_bom = this.index.cus_group_bom.filter(v=>v.dish_key_id !== res.id);
        this.index.cus_group_bom = cus_group_bom.concat(cus_group_dish_bom_list);

        if(isChangedName){
            isSetPlanWeekData = true;
        }
        if(isEdit){
            if(isSetPlanWeekData){
                this.setPlanWeekData(this.planWeekData);
            }else{
                this.gridOptions.api.redrawRows();
            }
        }

        return newDish;
    }

    //批量创建食材
    async addBatchMaterialAsync(data){
        // console.log(data);
        let _this = this;
        let res = [];
        let phaseArr = [
            {id:'p1_material',name:'食材'},
            {id:'p2_semi_dish',name:'半成品'},
            {id:'p3_dish',name:'成品'},
            {id:'p4_non_mm',name:'非食材'},
            {id:'p5_package',name:'套餐'},
        ];
        let default_unit_id = this.index.material_purchase_unit_category.find(v=>v.name == '斤').id;
        let default_process_id = this.default_process_id;
        let daily_cost_category_id = this.index.daily_cost_category[0].id;
        let top_category_id = this.index.material_top_category[0].id;

        let default_msupplier_id = this.default_msupplier_id;

        const asyncArrayMap = async (array, asyncFunction) => {
            const promises = array.map(asyncFunction);
            return await Promise.all(promises);
        };
        const asyncOperation = (v) => {
            let [mname,form,phaseName] = v.name.split('-');
            let phase = phaseArr.find(d=>d.name == phaseName).id;
            let item = {
                mm_id:v.mm_id,
                mname,
                form,
                phase,
                name:v.name,
                cutlist_qty_adjust:'pqa1_keep',
                purchase_qty_adjust:'pqa1_keep',
                in_out_way:'by_application',
                main_unit_id:default_unit_id,
                purchase_unit_id:default_unit_id,
                default_process_id,
                admin_ratio:0,
                purchase_unit_price:1,
                main_unit_ratio:1,
                purchase_unit_ratio:1,
                daily_cost_category_id,
                default_msupplier_id,
                out_days_ahead:'0',
                plan_day_purchase_ahead_days:'-1',
                purchase_first_to:"to_purchase",
                purchase_freq:'day',
                top_category_id,
                expansion:1
            };
            return _this.addMaterialAsync(item,false);
        };
        await asyncArrayMap(data, asyncOperation).then(result => {
            res = result;
        });
        return res;
    }

    // 提交食材创建/修改
    async addMaterialAsync(data, isEdit) {
        if (!data || data.name.trim() == '') {
            return 0
        }
        console.log('食材数据：',JSON.parse(JSON.stringify(data)));

        if(!data.purchase_unit_ratio){
            data.purchase_unit_ratio = this.getMaterialUnitJinRatio(data.id,data.purchase_unit_id);
        }
        if(!data.main_unit_ratio){
            data.main_unit_ratio = this.getMaterialUnitJinRatio(data.id,data.main_unit_id);
        }

        let res;
        if (this.props.PlanWeekUpdateMaterialItemVals) {
            res = await this.props.PlanWeekUpdateMaterialItemVals(data);
        } else {
            res = await this.requestMaterial(data);
        }

        let {material_id, main_price, main_unit_id, unit_ratio_obj_list,net_material_list,cost_center_material_cfg_list} = res;

        // console.assert(unit_ratio_obj_list.length >= data.unit_ratio_list.length);

        Object.assign(data, {
            id: material_id,
            main_price,
            main_unit_id
        });
        this.cost_center_material_cfg_obj[material_id] = cost_center_material_cfg_list;

        // let old_material_item = {};

        if (isEdit) {
            let index = this.index.material_item.findIndex(v => {
                return v.id == data.id
            });
            // old_material_item = JSON.parse(JSON.stringify(this.index.material_item[index]));
            this.index.material_item[index] = data;
            if(unit_ratio_obj_list.length > 0){
                let material_item_unit_ratio = this.index.material_item_unit_ratio.filter(v=>v.material_id != material_id);
                unit_ratio_obj_list.forEach((bom_obj, i) => {
                    let new_bom_unit_ratio = {
                        ...bom_obj,
                        material_id: data.id
                    };
                    material_item_unit_ratio.push(new_bom_unit_ratio);
                });
                this.index.material_item_unit_ratio = material_item_unit_ratio;
            }
        } else {
            data.net_material_id = net_material_list[0].id;
            this.index.material_item.push(data);
            unit_ratio_obj_list.forEach((bom_obj, i) => {
                let new_bom_unit_ratio = {
                    ...bom_obj,
                    material_id: data.id
                };
                // console.log(new_bom_unit_ratio);
                this.index.material_item_unit_ratio.push(new_bom_unit_ratio);
            });
            this.index.net_material = this.index.net_material.concat(net_material_list);
            this.net_material = toObj(this.index.net_material, 'id');
        }

        this.material_item = toObj(this.index.material_item, 'id');


        return data;
    }

    // 测试用的异步
    request(data) {
        let cus_group_dish_bom_list = data.dish_bom_list.map(v=>{
            return {
                ...v,
                dish_key_id:data.id
            }
        })
        let id = data.id;
        if((id+'').startsWith("virtual_")) {
            id += '_0'
        }
        return new Promise((resolve, reject) => {
            setTimeout(() => {
                let item = {
                    id: id,
                    is_fish:false,
                    is_organ:false,
                    is_semi_finished:false,
                    spicy:'spicy1',
                    is_cow:false,
                    is_dark_goose:false,
                    cus_group_dish_bom_list:cus_group_dish_bom_list
                };
                resolve(item);
            }, 1000);
        });
    }

    requestMaterial(data) {
        return new Promise((resolve, reject) => {
            let net_material_list = [];
            if(!data.net_material_id){
                net_material_list.push({
                    id:add_net_material_id(),
                    name:data.mname
                })
            }
            let cost_center_material_cfg_list = [{
                admin_ratio:data.admin_ratio,
                material_id:data.id,
                unit_id:data.purchase_unit_id,
                unit_price:data.purchase_unit_price
            }];
            let unit_ratio_obj_list = [{
                unit_id:data.main_unit_id,
                jin_ratio:data.main_unit_ratio,
                material_id:data.id
            }];
            if(data.main_unit_id!=data.purchase_unit_id){
                unit_ratio_obj_list.push({
                    unit_id:data.purchase_unit_id,
                    jin_ratio:data.purchase_unit_ratio,
                    material_id:data.id
                })
            }
            let main_price = data.purchase_unit_price*data.main_unit_ratio/data.purchase_unit_ratio;
            setTimeout(() => {
                resolve({
                    material_id: data.id || add_material_item_id(),
                    main_price: main_price,
                    main_unit_id: data.main_unit_id,
                    unit_ratio_obj_list:unit_ratio_obj_list,
                    // unit_ratio_obj_list: data.unit_ratio_list.length == 0 ? [] : data.unit_ratio_list.map(v => {
                    //     return v;
                    // }),
                    net_material_list:net_material_list,
                    cost_center_material_cfg_list:cost_center_material_cfg_list
                });
            }, 1000);
        });
    }
    requestUnit(data) {
        return new Promise((resolve, reject) => {
            setTimeout(() => {
                resolve({
                    unit_ratio_obj_list: data.length == 0 ? [] : data.map(v => {
                        return v;
                    })
                });
            }, 1000);
        });
    }

    // 菜品列表
    showDishListModal(filterModel,callback) {
        // console.log(this.state.DishLishModalOpen);
        this.state.DishLishData.filterModel = filterModel;
        this.state.DishLishData.callback = callback;
        this.state.DishLishModalOpen = true;
    }

    // 选择菜品
    selectDish(data) {
        if (typeof this.state.DishLishData.callback == 'function') {
            this.state.DishLishData.callback(data);
        }
        this.state.DishLishModalOpen = false;
    }

    checkboxChange(e){
        let key = e.target.dataset.name;
        let checked = e.target.checked;
        this.state.editConfig[key] = checked?'1':'0';
        this.limitChange();
    }

    //视图显示
    setVisible(e) {
        // console.log('-----setVisible---------');
        let key;
        if(typeof e == 'string'){
            key = e;
        }
        if(typeof e == 'object'){
            key = e.target.dataset.name;
        }
        let checked = this.state.tableConfig[key];
        if (['color', 'cost', 'spicy'].includes(key)) {
            this.refreshCells();
        }
        if(key == 'costRange'){
            let columns = ['minCost','maxCost'];
            this.gridOptions.columnApi.setColumnsVisible(columns, checked);
        }
        if(key == 'category'){
            let columns = dayKeys.map(v=>v+'_limit_category_name');
            this.gridOptions.columnApi.setColumnsVisible(columns, checked);
        }
    }
    setIsDishTipColor(e){
        this.refreshCells();
    }
    // 刷新表格
    refreshCells() {
        // console.log('-----refreshCells---------);
        this.gridOptions.api.refreshCells({force: true});
    }

    // 侧边栏展开/关闭
    toggleFilter() {
        this.state.sidebarShow = this.state.sidebarShow == 'hide' ? 'show' : 'hide';
    }

    // 展开/关闭
    toggleInfo() {
        this.state.infoShow = this.state.infoShow == 'hide' ? 'show' : 'hide';
    }

    // 辣度样式
    spicyHtml(spicy) {
        const spicy_svg = '<svg t="1677052790617" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5098" width="14" height="14"><path d="M536.243452 167.388639a20.92358 20.92358 0 0 0 20.92358-20.92358V20.92358a20.92358 20.92358 0 0 0-41.84716 0v125.541479a20.92358 20.92358 0 0 0 20.92358 20.92358zM658.842553 247.617491a160.771557 160.771557 0 0 0-119.826726-53.616674H538.8589a160.99387 160.99387 0 0 0-160.850021 160.850021v58.978341a2716.220678 2716.220678 0 0 1-26.324479 376.493665L324.771446 981.799755A36.472415 36.472415 0 0 0 344.779619 1020.02452a37.257049 37.257049 0 0 0 16.751941 3.923171 36.616265 36.616265 0 0 0 25.80139-10.762566 1067.887209 1067.887209 0 0 0 210.543522-293.597058A1067.8349 1067.8349 0 0 0 698.62351 372.701267a160.85002 160.85002 0 0 0-39.780957-125.083776z m-1.791581 120.402125A1031.937883 1031.937883 0 0 1 368.25326 973.116469l24.846751-177.052717A2757.531671 2757.531671 0 0 0 419.856039 413.750715v-58.978341a119.107479 119.107479 0 0 1 119.002861-119.00286h0.196158a118.819779 118.819779 0 0 1 118.035146 132.223947z" fill="#d81e06" p-id="5099"></path></svg>';
        const spicy_svg_0 = '<svg t="1677052790617" class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="5098" width="14" height="14"><path d="M536.243452 167.388639a20.92358 20.92358 0 0 0 20.92358-20.92358V20.92358a20.92358 20.92358 0 0 0-41.84716 0v125.541479a20.92358 20.92358 0 0 0 20.92358 20.92358zM658.842553 247.617491a160.771557 160.771557 0 0 0-119.826726-53.616674H538.8589a160.99387 160.99387 0 0 0-160.850021 160.850021v58.978341a2716.220678 2716.220678 0 0 1-26.324479 376.493665L324.771446 981.799755A36.472415 36.472415 0 0 0 344.779619 1020.02452a37.257049 37.257049 0 0 0 16.751941 3.923171 36.616265 36.616265 0 0 0 25.80139-10.762566 1067.887209 1067.887209 0 0 0 210.543522-293.597058A1067.8349 1067.8349 0 0 0 698.62351 372.701267a160.85002 160.85002 0 0 0-39.780957-125.083776z m-1.791581 120.402125A1031.937883 1031.937883 0 0 1 368.25326 973.116469l24.846751-177.052717A2757.531671 2757.531671 0 0 0 419.856039 413.750715v-58.978341a119.107479 119.107479 0 0 1 119.002861-119.00286h0.196158a118.819779 118.819779 0 0 1 118.035146 132.223947z" fill="#bfbfbf" p-id="5099"></path></svg>';
        let _html = '';
        spicy == 'spicy1' && (_html += `<span class="spicy-icon">${spicy_svg_0}${spicy_svg_0}${spicy_svg_0}</span>`);
        spicy == 'spicy2' && (_html += `<span class="spicy-icon">${spicy_svg_0}${spicy_svg_0}${spicy_svg}</span>`);
        spicy == 'spicy3' && (_html += `<span class="spicy-icon">${spicy_svg_0}${spicy_svg}${spicy_svg}</span>`);
        spicy == 'spicy4' && (_html += `<span class="spicy-icon">${spicy_svg}${spicy_svg}${spicy_svg}</span>`);
        return _html;
    }

    getMonday(type, dates) {
        var now = new Date();
        var nowTime = now.getTime();
        var day = now.getDay();
        // 如果是周日
        if(day == 0){
            dates = dates-1;
        }
        var longTime = 24 * 60 * 60 * 1000;
        var n = longTime * 7 * (dates || 0);
        if (type == "s") {
            var dd = nowTime - (day - 1) * longTime + n;
        };
        if (type == "e") {
            var dd = nowTime + (7 - day) * longTime + n;
        };
        dd = new Date(dd);
        var y = dd.getFullYear();
        var m = dd.getMonth() + 1;
        var d = dd.getDate();
        m = m < 10 ? "0" + m : m;
        d = d < 10 ? "0" + d : d;
        // var day = y + "-" + m + "-" + d;
        var day = m + "/" + d;
        return day;
    }

    get spicy() {
        return markup(this.spicyHtml('spicy2'))
    }

    DoUpdate() {
        alert('数据更新')
    }

    formatterTePeiStrToObj(t){
        let reg=/\{\{(\S*)\}\}/ ; // 正则表达式，注意两边的{}即是指定的字符
        !t && (t = '');
        t = t.replace(/\s+/g, "");
        let resultArr = t.match(reg);
        let dish_key_name = '';
        let dish_top_category_id = 0;
        if(!resultArr){
            dish_key_name = t;
        }else{
            dish_key_name = t.replace(resultArr[0],"");
            let dish_top_category_name = resultArr[1];
            try{
                dish_top_category_id = this.index.dish_top_category.find(v=>v.name_cn == dish_top_category_name).id;
            }catch (e) {}
        }

        let dish_key_id = this.getDishKeyIdByName(dish_key_name,dish_top_category_id);
        return {
            id:dish_key_id,
            name:dish_key_name,
            dish_top_category_id:dish_top_category_id
        }
    }
    formatterTePeiIdToStr(dish_key_id){
        if(!dish_key_id){
            return ''
        }
        let dish = this.dish_key[dish_key_id];
        let dish_top_category_name = '';
        try{
            dish_top_category_name = this.dish_top_category[dish.dish_top_category_id].name_cn||'';
        }catch (e) {

        }
        if(!dish_top_category_name){
           return dish.name
        }else{
            return dish.name + '{{'+dish_top_category_name+'}}';
        }
    }
}


Root.template = 'Plan_Week_Model_With_Cus_Overall_Show_Root';

Root.defaultProps = {
    model_no: '1',
}

Root.props = {
    model_no: {type: String,  optional: true},
    ImportPlanWeekModelData: {type: Function,  optional: true},
    DownLoadPlanWeekModelOverShowData: {type: Function,  optional: true},
    UpdateDishKeyVals: {type: Function,  optional: true},
    LoadDishKeyRelatedData: {type: Function,  optional: true},
    LoadMaterialRelatedData: {type: Function,  optional: true},
    UpdatePlanWeekModelWithCusOverShowData: {type: Function,  optional: true},
    GetSystemRecommendDataList: {type: Function,  optional: true},
    GetDishKeyRank: {type: Function,  optional: true},
    GetPlanWeekOverAllShowData: {type: Function,  optional: true},
    PlanWeekModelChangeModelNo: {type: Function,  optional: true},
    GeneratePlanWeekOverAllShowData: {type: Function,  optional: true},
    PlanWeekModelOverallShowDishKeyBom: {type: Function,  optional: true},
    LoadData: {type: Function,  optional: true},
    PlanWeekUpdateMaterialItemBomUnitRatioVals: {type: Function,  optional: true},
    PlanWeekUpdateMaterialItemVals: {type: Function,  optional: true},
    PlanWeekLoadSimilarDishBomData: {type: Function,  optional: true},
}

// console.log(t_root);
// console.log(init_grid_options);


Root.components = {
    CreatDishModal, DishListModal, Toast, FreqModal,ImportModal,CreatMaterialModal,UnitRatioModal
}


export {
    Root
}
